├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R └── rand_names.R ├── README.Rmd ├── README.md ├── cran-comments.md ├── man └── rand_names.Rd ├── randNames.Rproj └── tests ├── testthat.R └── testthat └── test_rand_names.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^\.travis\.yml$ 2 | README.Rmd 3 | cache/ 4 | .coveralls.yml 5 | cran-comments.md 6 | ^README\.Rmd$ 7 | ^README-.*\.png$ 8 | ^.*\.Rproj$ 9 | ^\.Rproj\.user$ 10 | randNames.Rproj 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cache/ 2 | .Rproj.user -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | warnings_are_errors: true 3 | sudo: required 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: randNames 2 | Title: Package Provides Access to Fake User Data 3 | Version: 0.2.3 4 | Authors@R: person("Karthik", "Ram", email = "karthik.ram@gmail.com", role = c("aut", "cre")) 5 | Description: Generates random names with additional information including fake 6 | SSNs, gender, location, zip, age, address, and nationality. 7 | Depends: 8 | R (>= 3.1.2) 9 | Date: 2016-07-01 10 | URL: https://github.com/karthik/randNames 11 | BugReports: https://github.com/karthik/randNames/issues 12 | License: MIT + file LICENSE 13 | LazyData: true 14 | Imports: 15 | tibble, 16 | httr, 17 | jsonlite 18 | Suggests: 19 | testthat 20 | RoxygenNote: 5.0.1 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2015 2 | COPYRIGHT HOLDER: Karthik Ram -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(rand_names) 4 | import(httr) 5 | importFrom(jsonlite,fromJSON) 6 | importFrom(tibble,as_data_frame) 7 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | version 0.2.3 2 | ============ 3 | * Minor bug fix. Replaced `tibble_df` with `as_data_frame` 4 | 5 | version 0.2.2 6 | ============ 7 | * Minor bug fixes 8 | * API has dropped `user` from all field names so package has been updated accordingly. 9 | 10 | version 0.2.1 11 | ============ 12 | * Minor bug fix to accommodate API update 13 | 14 | version 0.2 15 | ============ 16 | * Initial release to CRAN 17 | -------------------------------------------------------------------------------- /R/rand_names.R: -------------------------------------------------------------------------------- 1 | #' Random name generator 2 | #' 3 | #' This function grabs a list of random names from the random user generator 4 | #' 5 | #' The return object contains the following fields: seed, user.password, 6 | #' user.sha256, user.cell, user.name.title, user.location.city, 7 | #' user.picture.medium, user.gender, user.salt, user.registered, user.SSN, 8 | #' user.name.first, user.location.state, user.picture.thumbnail, user.email, 9 | #' user.md5, user.dob, user.version, user.name.last, user.location.zip, 10 | #' user.NINO, user.username, user.sha1, user.phone, user.nationality, 11 | #' user.location.street, user.picture.large. 12 | #' 13 | #' @param n Number of names required. Free users get 100 max and registered RandomAPI users get 500 max. 14 | #' Register for a free API key here: \url{https://randomapi.com} 15 | #' @param seed A random string to ensure same results 16 | #' @param gender male or female 17 | #' @param nationality Currently takes: \code{AU}, \code{BR}, \code{CA}, \code{CH}, \code{DE}, \code{DK}, \code{ES}, \code{FI}, \code{FR}, \code{GB}, \code{IE}, \code{IR}, \code{NL}, \code{NZ}, \code{TR}, \code{US} 18 | #' @param key An API key for more results per request (500 max for registered RandomAPI users). 19 | #' @import httr 20 | #' @importFrom jsonlite fromJSON 21 | #' @importFrom tibble as_data_frame 22 | #' @export 23 | #' @examples 24 | #' data <- rand_names(5) 25 | #' # dplyr::select(data, first = name.first, last = name.last) 26 | #' 27 | #' # x <- 5 %>% 28 | #' # rand_names %>% 29 | #' # dplyr::filter(gender == "female") %>% 30 | #' # dplyr::select(name.first, name.last) 31 | rand_names <- function(n = 1, seed = NULL, gender = NULL, nationality = NULL, key = NULL) { 32 | ee_compact <- function(l) Filter(Negate(is.null), l) 33 | args <- ee_compact(as.list(c(results = n, 34 | seed = seed, 35 | gender = gender, 36 | nat = nationality, 37 | key = key))) 38 | if(n > 0) { 39 | # Make api call 40 | r <- httr::GET("http://api.randomuser.me/", 41 | query = args) 42 | # Check if it raised an error 43 | httr::stop_for_status(r) 44 | # Interpret it 45 | x <- jsonlite::fromJSON(httr::content(r, as = "text"), flatten = TRUE) 46 | } 47 | tibble::as_data_frame(x$results) 48 | } -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | 2 | # Random names 3 | 4 | [![Travis-CI Build Status](https://travis-ci.org/karthik/randNames.png?branch=master)](https://travis-ci.org/karthik/randNames) [![Coverage Status](https://coveralls.io/repos/karthik/randNames/badge.svg)](https://coveralls.io/r/karthik/randNames) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/randNames)](https://cran.r-project.org/package=randNames) [![](http://cranlogs.r-pkg.org/badges/randNames)](http://cran.rstudio.com/web/packages/randNames/index.html) 5 | 6 | The package provides a programmatic interface to the Random Names API and returns 'sample' user data including fake first/last names, emails, SSNs, addresses, avatars and more. Search queries can be further filtered by gender and nationality. 7 | 8 | ```{r, echo = FALSE, message = FALSE} 9 | knitr::opts_chunk$set( 10 | comment = "#>", 11 | cache = FALSE, 12 | error = FALSE, 13 | message = FALSE, 14 | tidy = FALSE 15 | ) 16 | ``` 17 | 18 | **Installation** 19 | 20 | ```{r, eval = FALSE} 21 | install.packages("randNames") 22 | ```` 23 | 24 | or for the development version 25 | ```{r, eval = FALSE} 26 | devtools::install_github("karthik/randNames") 27 | ``` 28 | 29 | It queries a random name API and returns a whole bunch of useful fields. 30 | 31 | ```{r, names, cache = TRUE} 32 | library(dplyr) 33 | library(randNames) 34 | 20 %>% 35 | rand_names %>% 36 | select(first = name.first, last = name.last) 37 | ``` 38 | 39 | __Filter by nationality__ 40 | 41 | ```{r, nationality, cache = TRUE} 42 | 15 %>% 43 | # Available nationalities: AU, BR, CA, CH, DE, DK, ES, FI, FR, GB, IE, IR, NL, NZ, TR, US 44 | # You can specify multiple nationalities. e.g. "gb,us" 45 | rand_names(nationality = "GB") %>% 46 | select(name.first, name.last) 47 | ``` 48 | 49 | __Filter by gender__ 50 | 51 | ```{r, gender} 52 | library(randNames) 53 | 15 %>% 54 | rand_names(gender = "female") %>% 55 | select(name.first, name.last) 56 | ``` 57 | 58 | 59 | __Set seed__ 60 | 61 | ```{r, seed} 62 | 15 %>% 63 | rand_names(seed = 'foobar') %>% 64 | select(name.first, name.last) 65 | ``` 66 | 67 | __Additional fields beyond first and last name__ 68 | 69 | 70 | ``` 71 | gender 72 | email 73 | registered" 74 | dob 75 | phone 76 | cell 77 | nat 78 | name.title 79 | name.first 80 | name.last 81 | location.street 82 | location.city 83 | location.state 84 | location.postcode 85 | login.username" 86 | login.password 87 | login.salt 88 | login.md5 89 | login.sha1 90 | login.sha256 91 | id.name 92 | id.value 93 | picture.large 94 | picture.medium 95 | picture.thumbnail 96 | ``` 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Random names 3 | 4 | [![Travis-CI Build Status](https://travis-ci.org/karthik/randNames.png?branch=master)](https://travis-ci.org/karthik/randNames) [![Coverage Status](https://coveralls.io/repos/karthik/randNames/badge.svg)](https://coveralls.io/r/karthik/randNames) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/randNames)](https://cran.r-project.org/package=randNames) [![](http://cranlogs.r-pkg.org/badges/randNames)](http://cran.rstudio.com/web/packages/randNames/index.html) 5 | 6 | The package provides a programmatic interface to the Random Names API and returns 'sample' user data including fake first/last names, emails, SSNs, addresses, avatars and more. Search queries can be further filtered by gender and nationality. 7 | 8 | 9 | 10 | **Installation** 11 | 12 | 13 | ```r 14 | install.packages("randNames") 15 | ``` 16 | 17 | or for the development version 18 | 19 | ```r 20 | devtools::install_github("karthik/randNames") 21 | ``` 22 | 23 | It queries a random name API and returns a whole bunch of useful fields. 24 | 25 | 26 | ```r 27 | library(dplyr) 28 | library(randNames) 29 | 20 %>% 30 | rand_names %>% 31 | select(first = name.first, last = name.last) 32 | ``` 33 | 34 | ``` 35 | #> Source: local data frame [20 x 2] 36 | #> 37 | #> first last 38 | #> (chr) (chr) 39 | #> 1 nalan demirbaş 40 | #> 2 danielle lord 41 | #> 3 nurdan sepetçi 42 | #> 4 julie miles 43 | #> 5 vedat akyürek 44 | #> 6 doris jimenez 45 | #> 7 cícero pinto 46 | #> 8 salvador brooks 47 | #> 9 florian leclercq 48 | #> 10 wyatt harris 49 | #> 11 caroline christensen 50 | #> 12 علی رضا نكو نظر 51 | #> 13 megan mitchell 52 | #> 14 anthony ennis 53 | #> 15 bryan cook 54 | #> 16 jessie tucker 55 | #> 17 mia ryan 56 | #> 18 luis legrand 57 | #> 19 iolene barbosa 58 | #> 20 line david 59 | ``` 60 | 61 | __Filter by nationality__ 62 | 63 | 64 | ```r 65 | 15 %>% 66 | # Available nationalities: AU, BR, CA, CH, DE, DK, ES, FI, FR, GB, IE, IR, NL, NZ, TR, US 67 | # You can specify multiple nationalities. e.g. "gb,us" 68 | rand_names(nationality = "GB") %>% 69 | select(name.first, name.last) 70 | ``` 71 | 72 | ``` 73 | #> Source: local data frame [15 x 2] 74 | #> 75 | #> name.first name.last 76 | #> 77 | #> 1 emily brooks 78 | #> 2 lillian stanley 79 | #> 3 gerald henderson 80 | #> 4 alison gilbert 81 | #> 5 henry simpson 82 | #> 6 albert robertson 83 | #> 7 nolan reynolds 84 | #> 8 sarah palmer 85 | #> 9 molly rodriquez 86 | #> 10 peter walters 87 | #> 11 benjamin larson 88 | #> 12 sheryl payne 89 | #> 13 eliza kim 90 | #> 14 kent mitchelle 91 | #> 15 tyrone holmes 92 | ``` 93 | 94 | __Filter by gender__ 95 | 96 | 97 | ```r 98 | library(randNames) 99 | 15 %>% 100 | rand_names(gender = "female") %>% 101 | select(name.first, name.last) 102 | ``` 103 | 104 | ``` 105 | #> Source: local data frame [15 x 2] 106 | #> 107 | #> name.first name.last 108 | #> 109 | #> 1 abigail price 110 | #> 2 sofia ylitalo 111 | #> 3 marika dobbe 112 | #> 4 ella andersen 113 | #> 5 fransien van plateringen 114 | #> 6 séléna dubois 115 | #> 7 tansu potman 116 | #> 8 megan bouchard 117 | #> 9 lotta kallio 118 | #> 10 lily williams 119 | #> 11 anaïs leclerc 120 | #> 12 iida kokko 121 | #> 13 laura rodriguez 122 | #> 14 غزل پارسا 123 | #> 15 emma douglas 124 | ``` 125 | 126 | 127 | __Set seed__ 128 | 129 | 130 | ```r 131 | 15 %>% 132 | rand_names(seed = 'foobar') %>% 133 | select(name.first, name.last) 134 | ``` 135 | 136 | ``` 137 | #> Source: local data frame [15 x 2] 138 | #> 139 | #> name.first name.last 140 | #> 141 | #> 1 becky sims 142 | #> 2 amelia anderson 143 | #> 3 vilho lampinen 144 | #> 4 maëlle robert 145 | #> 5 kasper palo 146 | #> 6 macit kılıççı 147 | #> 7 alexis walker 148 | #> 8 cléa rousseau 149 | #> 9 allert thielen 150 | #> 10 jasper li 151 | #> 11 çetin adan 152 | #> 12 ray cunningham 153 | #> 13 lewis morris 154 | #> 14 yann roche 155 | #> 15 elli niskanen 156 | ``` 157 | 158 | __Additional fields beyond first and last name__ 159 | 160 | 161 | ``` 162 | gender 163 | email 164 | registered" 165 | dob 166 | phone 167 | cell 168 | nat 169 | name.title 170 | name.first 171 | name.last 172 | location.street 173 | location.city 174 | location.state 175 | location.postcode 176 | login.username" 177 | login.password 178 | login.salt 179 | login.md5 180 | login.sha1 181 | login.sha256 182 | id.name 183 | id.value 184 | picture.large 185 | picture.medium 186 | picture.thumbnail 187 | ``` 188 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | Package has undergone a minor update to replace `tibble_df` with `as_data_frame` since the former function is no longer being exported by the `tibble` package. 2 | -------------------------------------------------------------------------------- /man/rand_names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rand_names.R 3 | \name{rand_names} 4 | \alias{rand_names} 5 | \title{Random name generator} 6 | \usage{ 7 | rand_names(n = 1, seed = NULL, gender = NULL, nationality = NULL, 8 | key = NULL) 9 | } 10 | \arguments{ 11 | \item{n}{Number of names required. Free users get 100 max and registered RandomAPI users get 500 max. 12 | Register for a free API key here: \url{https://randomapi.com}} 13 | 14 | \item{seed}{A random string to ensure same results} 15 | 16 | \item{gender}{male or female} 17 | 18 | \item{nationality}{Currently takes: \code{AU}, \code{BR}, \code{CA}, \code{CH}, \code{DE}, \code{DK}, \code{ES}, \code{FI}, \code{FR}, \code{GB}, \code{IE}, \code{IR}, \code{NL}, \code{NZ}, \code{TR}, \code{US}} 19 | 20 | \item{key}{An API key for more results per request (500 max for registered RandomAPI users).} 21 | } 22 | \description{ 23 | This function grabs a list of random names from the random user generator 24 | } 25 | \details{ 26 | The return object contains the following fields: seed, user.password, 27 | user.sha256, user.cell, user.name.title, user.location.city, 28 | user.picture.medium, user.gender, user.salt, user.registered, user.SSN, 29 | user.name.first, user.location.state, user.picture.thumbnail, user.email, 30 | user.md5, user.dob, user.version, user.name.last, user.location.zip, 31 | user.NINO, user.username, user.sha1, user.phone, user.nationality, 32 | user.location.street, user.picture.large. 33 | } 34 | \examples{ 35 | data <- rand_names(5) 36 | # dplyr::select(data, first = name.first, last = name.last) 37 | 38 | # x <- 5 \%>\% 39 | # rand_names \%>\% 40 | # dplyr::filter(gender == "female") \%>\% 41 | # dplyr::select(name.first, name.last) 42 | } 43 | 44 | -------------------------------------------------------------------------------- /randNames.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(randNames) 3 | 4 | test_check("randNames") 5 | -------------------------------------------------------------------------------- /tests/testthat/test_rand_names.R: -------------------------------------------------------------------------------- 1 | context("Testing rand names works") 2 | 3 | test_that("Random names work", { 4 | expect_is(rand_names(1), 'data.frame') 5 | }) 6 | --------------------------------------------------------------------------------