Skip to content

Commit

Permalink
add accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Keyes committed Aug 27, 2015
1 parent af510d2 commit d69ddec
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ Suggests:
testthat,
knitr
LinkingTo: Rcpp
Imports: Rcpp
Imports:
Rcpp,
methods
VignetteBuilder: knitr
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Generated by roxygen2 (4.1.1): do not edit by hand

export("first_name<-")
export("last_name<-")
export("middle_name<-")
export("salutation<-")
export("suffix<-")
export(first_name)
export(format_period)
export(format_reverse)
export(last_name)
export(middle_name)
export(parse_names)
export(salutation)
export(suffix)
import(methods)
importFrom(Rcpp,sourceCpp)
useDynLib(humaniformat)
169 changes: 169 additions & 0 deletions R/accessors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#'@title Get or set a name's saltation
#'@description as in the lubridate package, individual components of a name
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'@aliases salutation
#'@rdname salutation
#'
#'@param x a name, or vector of names
#'
#'@param value a replacement value for x's salutation
#'
#'@seealso \code{\link{first_name}}, \code{\link{middle_name}}, \code{\link{last_name}}
#'and \code{\link{suffix}} for other accessors.
#'
#'@examples
#'#Get a salutation
#'example_name <- "Mr Jim Jeffries"
#'salutation(example_name)
#'
#'#Set a salutation
#'salutation(example_name) <- "Prof"
#'@import methods
#'@export
salutation <- function(x){
return(get_(x,0))
}

"salutation<-" <- function(x, value) standardGeneric("salutation<-")
#'@rdname salutation
#'@export
setGeneric("salutation<-", useAsDefault = function(x, value){
return(set_(x, 0, value))
})

#'@title Get or set a name's first name
#'@description as in the lubridate package, individual components of a name
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'@aliases first_name
#'@rdname first_name
#'
#'@param x a name, or vector of names
#'
#'@param value a replacement value for x's first name.
#'
#'@seealso \code{\link{salutation}}, \code{\link{middle_name}}, \code{\link{last_name}}
#'and \code{\link{suffix}} for other accessors.
#'
#'@examples
#'#Get a first name
#'example_name <- "Mr Jim Jeffries"
#'first_name(example_name)
#'
#'#Set a first name
#'first_name(example_name) <- "Prof"
#'@import methods
#'@export
first_name <- function(x){
return(get_(x,1))
}

"first_name<-" <- function(x, value) standardGeneric("first_name<-")
#'@rdname first_name
#'@export
setGeneric("first_name<-", useAsDefault = function(x, value){
return(set_(x, 1, value))
})

#'@title Get or set a name's middle name
#'@description as in the lubridate package, individual components of a name
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'@aliases middle_name
#'@rdname middle_name
#'
#'@param x a name, or vector of names
#'
#'@param value a replacement value for x's middle name.
#'
#'@seealso \code{\link{salutation}}, \code{\link{first_name}}, \code{\link{last_name}}
#'and \code{\link{suffix}} for other accessors.
#'
#'@examples
#'#Get a middle name
#'example_name <- "Mr Jim Toby Jeffries"
#'middle_name(example_name)
#'
#'#Set a middle name
#'middle_name(example_name) <- "Richard"
#'@import methods
#'@export
middle_name <- function(x){
return(get_(x, 2))
}

"middle_name<-" <- function(x, value) standardGeneric("middle_name<-")
#'@rdname middle_name
#'@export
setGeneric("middle_name<-", useAsDefault = function(x, value){
return(set_(x, 2, value))
})

#'@title Get or set a name's last name
#'@description as in the lubridate package, individual components of a name
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'@aliases last_name
#'@rdname last_name
#'
#'@param x a name, or vector of names
#'
#'@param value a replacement value for x's last name.
#'
#'@seealso \code{\link{salutation}}, \code{\link{first_name}}, \code{\link{middle_name}}
#'and \code{\link{suffix}} for other accessors.
#'
#'@examples
#'#Get a last name
#'example_name <- "Mr Jim Toby Jeffries"
#'last_name(example_name)
#'
#'#Set a last name
#'last_name(example_name) <- "Smith"
#'@import methods
#'@export
last_name <- function(x){
return(get_(x, 3))
}

"last_name<-" <- function(x, value) standardGeneric("last_name<-")
#'@rdname last_name
#'@export
setGeneric("last_name<-", useAsDefault = function(x, value){
return(set_(x, 3, value))
})

#'@title Get or set a name's suffix
#'@description as in the lubridate package, individual components of a name
#'can be both extracted or set using the relevant function call - see the
#'examples.
#'@aliases suffix
#'@rdname suffix
#'
#'@param x a name, or vector of names
#'
#'@param value a replacement value for x's suffix.
#'
#'@seealso \code{\link{salutation}}, \code{\link{first_name}}, \code{\link{middle_name}}
#'and \code{\link{last_name}} for other accessors.
#'
#'@examples
#'#Get a suffix]
#'example_name <- "Mr Jim Toby Jeffries Esq"
#'suffix(example_name)
#'
#'#Set a suffix
#'suffix(example_name) <- "PhD"
#'@import methods
#'@export
suffix <- function(x){
return(get_(x, 4))
}

"suffix<-" <- function(x, value) standardGeneric("suffix<-")
#'@rdname suffix
#'@export
setGeneric("suffix<-", useAsDefault = function(x, value){
return(set_(x, 4, value))
})
34 changes: 34 additions & 0 deletions man/first_name.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/accessors.R
\name{first_name}
\alias{first_name}
\alias{first_name<-}
\title{Get or set a name's first name}
\usage{
first_name(x)
first_name(x) <- value
}
\arguments{
\item{x}{a name, or vector of names}
\item{value}{a replacement value for x's first name.}
}
\description{
as in the lubridate package, individual components of a name
can be both extracted or set using the relevant function call - see the
examples.
}
\examples{
#Get a first name
example_name <- "Mr Jim Jeffries"
first_name(example_name)

#Set a first name
first_name(example_name) <- "Prof"
}
\seealso{
\code{\link{salutation}}, \code{\link{middle_name}}, \code{\link{last_name}}
and \code{\link{suffix}} for other accessors.
}

34 changes: 34 additions & 0 deletions man/last_name.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/accessors.R
\name{last_name}
\alias{last_name}
\alias{last_name<-}
\title{Get or set a name's last name}
\usage{
last_name(x)
last_name(x) <- value
}
\arguments{
\item{x}{a name, or vector of names}
\item{value}{a replacement value for x's last name.}
}
\description{
as in the lubridate package, individual components of a name
can be both extracted or set using the relevant function call - see the
examples.
}
\examples{
#Get a last name
example_name <- "Mr Jim Toby Jeffries"
last_name(example_name)

#Set a last name
last_name(example_name) <- "Smith"
}
\seealso{
\code{\link{salutation}}, \code{\link{first_name}}, \code{\link{middle_name}}
and \code{\link{suffix}} for other accessors.
}

34 changes: 34 additions & 0 deletions man/middle_name.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/accessors.R
\name{middle_name}
\alias{middle_name}
\alias{middle_name<-}
\title{Get or set a name's middle name}
\usage{
middle_name(x)
middle_name(x) <- value
}
\arguments{
\item{x}{a name, or vector of names}
\item{value}{a replacement value for x's middle name.}
}
\description{
as in the lubridate package, individual components of a name
can be both extracted or set using the relevant function call - see the
examples.
}
\examples{
#Get a middle name
example_name <- "Mr Jim Toby Jeffries"
middle_name(example_name)

#Set a middle name
middle_name(example_name) <- "Richard"
}
\seealso{
\code{\link{salutation}}, \code{\link{first_name}}, \code{\link{last_name}}
and \code{\link{suffix}} for other accessors.
}

34 changes: 34 additions & 0 deletions man/salutation.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/accessors.R
\name{salutation}
\alias{salutation}
\alias{salutation<-}
\title{Get or set a name's saltation}
\usage{
salutation(x)
salutation(x) <- value
}
\arguments{
\item{x}{a name, or vector of names}
\item{value}{a replacement value for x's salutation}
}
\description{
as in the lubridate package, individual components of a name
can be both extracted or set using the relevant function call - see the
examples.
}
\examples{
#Get a salutation
example_name <- "Mr Jim Jeffries"
salutation(example_name)

#Set a salutation
salutation(example_name) <- "Prof"
}
\seealso{
\code{\link{first_name}}, \code{\link{middle_name}}, \code{\link{last_name}}
and \code{\link{suffix}} for other accessors.
}

34 changes: 34 additions & 0 deletions man/suffix.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/accessors.R
\name{suffix}
\alias{suffix}
\alias{suffix<-}
\title{Get or set a name's suffix}
\usage{
suffix(x)
suffix(x) <- value
}
\arguments{
\item{x}{a name, or vector of names}
\item{value}{a replacement value for x's suffix.}
}
\description{
as in the lubridate package, individual components of a name
can be both extracted or set using the relevant function call - see the
examples.
}
\examples{
#Get a suffix]
example_name <- "Mr Jim Toby Jeffries Esq"
suffix(example_name)

#Set a suffix
suffix(example_name) <- "PhD"
}
\seealso{
\code{\link{salutation}}, \code{\link{first_name}}, \code{\link{middle_name}}
and \code{\link{last_name}} for other accessors.
}

0 comments on commit d69ddec

Please sign in to comment.