charlatan
makes fake data, inspired from and borrowing some code from Python’s faker
Why would you want to make fake data? Here’s some possible use cases to give you a sense for what you can do with this package:
See the Contributing to charlatan vignette
R6
objects that a user can initialize and then call methods on. These contain all the logic that the below interfaces use.ch_*()
that wrap low level interfaces, and are meant to be easier to use and provide an easy way to make many instances of a thing.ch_generate()
- generate a data.frame with fake data, choosing which columns to include from the data types provided in charlatan
fraudster()
- single interface to all fake data methods, - returns vectors/lists of data - this function wraps the ch_*()
functions described aboveStable version from CRAN
install.packages("charlatan")
Development version from Github
devtools::install_github("ropensci/charlatan")
library("charlatan")
… for all fake data operations
x <- fraudster()
x$job()
#> [1] "Engineer, automotive"
x$name()
#> [1] "Ms. Aleta O'Kon DDS"
x$job()
#> [1] "Occupational therapist"
x$color_name()
#> [1] "GreenYellow"
Adding more locales through time, e.g.,
Locale support for job data
ch_job(locale = "en_US", n = 3)
#> [1] "Broadcast engineer" "Product designer"
#> [3] "Research scientist (medical)"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Hydraulicien"
#> [2] "Technicien d'exploitation de l'eau"
#> [3] "Conseiller en économie sociale et familiale"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Fizioterapeutski tehničar"
#> [2] "Odgajatelj u učeničkom domu"
#> [3] "Odgovorna osoba za ocjenjivanje sukladnosti građevinskih proizvoda"
ch_job(locale = "uk_UA", n = 3)
#> [1] "Бібліограф" "Секретар" "Астроном"
ch_job(locale = "zh_TW", n = 3)
#> [1] "生管助理" "客戶服務人員" "心理學研究人員"
For colors:
ch_color_name(locale = "en_US", n = 3)
#> [1] "Cyan" "PapayaWhip" "SteelBlue"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Циннвальдит" "Лазуровий" "Ультрамариновий"
More coming soon …
ch_generate()
#> # A tibble: 10 x 3
#> name job phone_number
#> <chr> <chr> <chr>
#> 1 Raymon Donnelly Sports administrator 1-411-205-0557x5577
#> 2 Miss Lavinia Baumbach … Theatre director 233.994.1552x8646
#> 3 Lora Collier DVM Health and safety adviser 1-823-830-2291x4940
#> 4 Mr. Dean Beahan DDS Senior tax professional/tax insp… 554-742-9675
#> 5 Lyda Ryan Database administrator (917)024-9152x4035
#> 6 Frida Armstrong Hydrologist 1-041-553-5156x541…
#> 7 Rufus Howell-Koelpin Engineer, structural 485.333.1282x2256
#> 8 Louvenia VonRueden Therapist, art 686.933.8333
#> 9 Mellisa Keeling Exhibitions officer, museum/gall… (229)582-6317x324
#> 10 Callie McDermott Chartered management accountant 869.393.1925x77477
ch_generate('job', 'phone_number', n = 30)
#> # A tibble: 30 x 2
#> job phone_number
#> <chr> <chr>
#> 1 English as a second language teacher (446)462-8829x54784
#> 2 Company secretary 179.566.0567x187
#> 3 Clothing/textile technologist 1-175-044-1387
#> 4 Technical sales engineer 830-117-2214
#> 5 Economist +19(8)9889303313
#> 6 Nurse, mental health (789)114-2432x2078
#> 7 Merchant navy officer +83(9)6026295373
#> 8 English as a foreign language teacher 1-573-165-9844x12523
#> 9 Medical technical officer 1-403-479-2141
#> 10 Engineer, civil (contracting) 1-690-568-3657
#> # … with 20 more rows
ch_name()
#> [1] "Grace Deckow"
ch_name(10)
#> [1] "Elbridge Dooley Sr." "Zaida Stracke" "Enrique VonRueden"
#> [4] "Mr. Verle Koss" "Hildred Conn" "Kenyon Howell III"
#> [7] "Delma Mertz" "Shona Stark" "Dr. Vonetta Armstrong"
#> [10] "Dr. Vashti Bailey PhD"
ch_phone_number()
#> [1] "1-835-651-8717"
ch_phone_number(10)
#> [1] "(604)405-5027" "126-480-4735x48552" "1-086-496-1111x36766"
#> [4] "042-754-0729x558" "332.006.1737x456" "006.891.7617"
#> [7] "275.525.7273x319" "1-873-705-3585" "1-122-719-7284x2682"
#> [10] "649.394.9233x2258"
ch_job()
#> [1] "Geologist, wellsite"
ch_job(10)
#> [1] "Trading standards officer" "Physicist, medical"
#> [3] "Energy engineer" "Hydrographic surveyor"
#> [5] "Medical illustrator" "Designer, fashion/clothing"
#> [7] "Statistician" "Health service manager"
#> [9] "Transport planner" "Air traffic controller"
ch_credit_card_provider()
#> [1] "Diners Club / Carte Blanche"
ch_credit_card_provider(n = 4)
#> [1] "Voyager" "Voyager" "VISA 13 digit" "JCB 15 digit"
ch_credit_card_number()
#> [1] "3492673232590227"
ch_credit_card_number(n = 10)
#> [1] "3034632417047426" "060495293791547" "6011320717243771773"
#> [4] "4220373428719897" "3088879464576096560" "4437842902292"
#> [7] "4266417098802460" "869988023143281969" "869956493318574944"
#> [10] "52577607417221095"
ch_credit_card_security_code()
#> [1] "4848"
ch_credit_card_security_code(10)
#> [1] "478" "453" "0035" "928" "610" "303" "263" "064" "191" "235"
charlatan
makes it very easy to generate fake data with missing entries. First, you need to run MissingDataProvider()
and then make an appropriate make_missing()
call specifying the data type to be generated. This method picks a random number (N
) of slots in the input make_missing
vector and then picks N
random positions that will be replaced with NA matching the input class.
testVector <- MissingDataProvider$new()
testVector$make_missing(x = ch_generate()$name)
#> [1] NA "Vivien Pacocha-McDermott"
#> [3] "Glendora VonRueden" NA
#> [5] "Dr. Nicolas Lehner" NA
#> [7] "Megan Bartell" NA
#> [9] NA "Lelia Emard"
testVector$make_missing(x = ch_integer(10))
#> [1] NA NA 635 NA 29 NA 582 NA NA NA
set.seed(123)
testVector$make_missing(x = sample(c(TRUE, FALSE), 10, replace = TRUE))
#> [1] TRUE NA NA FALSE TRUE NA FALSE FALSE NA TRUE
Real data is messy, right? charlatan
makes it easy to create messy data. This is still in the early stages so is not available across most data types and languages, but we’re working on it.
For example, create messy names:
ch_name(50, messy = TRUE)
#> [1] "Destiney Dicki" "Mrs Freddie Pouros d.d.s."
#> [3] "Jefferey Lesch" "Inga Dach"
#> [5] "Keyshawn Schaefer" "Ferdinand Bergstrom"
#> [7] "Justen Simonis" "Ms. Doloris Stroman md"
#> [9] "Mrs Ermine Heidenreich" "Marion Corwin"
#> [11] "Jalen Grimes" "Mr. Sullivan Hammes IV"
#> [13] "Adrien Vandervort-Dickens" "Dr Sharif Kunde"
#> [15] "Marlena Reichert d.d.s." "Mr. Brandan Oberbrunner"
#> [17] "Lloyd Adams Sr" "Keesha Schowalter"
#> [19] "Randy Ziemann" "Gina Sanford"
#> [21] "Cornell Funk" "Yadiel Collier"
#> [23] "Kamryn Johnson" "Tyesha Schmeler"
#> [25] "Ernie Hegmann-Graham" "Zackery Runolfsdottir"
#> [27] "Cleveland Predovic" "Melvyn Hickle"
#> [29] "Larry Nienow I" "Nicola Langosh Ph.D."
#> [31] "Ebenezer Fadel V" "Andrae Hand-Eichmann"
#> [33] "Shamar Harvey" "Miss Lynn Altenwerth"
#> [35] "Willene McLaughlin-Mohr" "Kyree Kutch"
#> [37] "Ms Delpha Grant" "Ms. Icie Crooks"
#> [39] "Loney Jenkins-Lindgren" "Shania Donnelly DVM"
#> [41] "Dr Patric Veum" "Amirah Rippin DVM"
#> [43] "Randle Hilpert" "Soren Dare"
#> [45] "Roderic Walter" "Farah Daugherty DDS"
#> [47] "Ryland Ledner" "Girtha Harvey DVM"
#> [49] "Tyrique Spencer" "Mr Olan Bernhard"
Right now only suffixes and prefixes for names in en_US
locale are supported. Notice above some variation in prefixes and suffixes.