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] "Therapist, art"
x$name()
#> [1] "Davion Murazik"
x$job()
#> [1] "TEFL teacher"
x$color_name()
#> [1] "LemonChiffon"
Adding more locales through time, e.g.,
Locale support for job data
ch_job(locale = "en_US", n = 3)
#> [1] "Counsellor" "Ecologist" "Financial trader"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Magasinier cariste" "Psychomotricien" "Animateur nature"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Glavni inspektor zaštite okoliša" "Pregledač vagona"
#> [3] "Ovlašteni revizor"
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] "DarkOrange" "BurlyWood" "PaleGoldenRod"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Грушевий" "Фіолетовий" "Темно-брунатний"
More coming soon …
ch_generate()
#> # A tibble: 10 × 3
#> name job phone_number
#> <chr> <chr> <chr>
#> 1 Kittie Bayer Accountant, chartered 790.477.8132x020
#> 2 Geraldo Zulauf Commissioning editor +68(7)2415815539
#> 3 Adelard Hegmann Psychologist, clinical 001.148.3692x348
#> 4 Cleola Hettinger Restaurant manager, fast food 09506901409
#> 5 Mrs. Nathalia Zulauf Equality and diversity officer +75(1)4803864411
#> 6 Edw Braun Geophysicist/field seismologist 755.845.0201x0508
#> 7 Miss Jaunita Effertz PhD Retail manager 767.075.3022x81938
#> 8 Nancy Konopelski Administrator, local government 1-772-466-7294x67130
#> 9 Coleman Rosenbaum-Schoen Diagnostic radiographer 1-010-738-7626
#> 10 Mrs. Gwenda Powlowski MD Race relations officer 1-879-063-1092x075
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#> job phone_number
#> <chr> <chr>
#> 1 Analytical chemist (920)534-8748
#> 2 Civil Service fast streamer +77(3)6668585195
#> 3 Records manager 763-920-4265x808
#> 4 Warehouse manager 848-525-1824x02934
#> 5 Community arts worker (604)257-5008x903
#> 6 Education officer, community 575-747-2541x31955
#> 7 Probation officer 813.941.1881x1840
#> 8 Curator 157-567-8891x6362
#> 9 Physiotherapist 813.191.2143x0886
#> 10 Volunteer coordinator (078)547-6492
#> # ℹ 20 more rows
ch_name()
#> [1] "Kenny Friesen"
ch_name(10)
#> [1] "Pleasant Adams" "Mr. Milford Gorczany PhD"
#> [3] "Deegan Towne" "Chaim Heathcote"
#> [5] "Ephram Bode-Heaney" "Orlo Bernhard"
#> [7] "Gauge Feest" "Dr. Marcelino Tromp DVM"
#> [9] "Sylas Wisoky DVM" "Gunda Considine"
ch_phone_number()
#> [1] "1-297-334-6249x463"
ch_phone_number(10)
#> [1] "185.236.9339x198" "135-587-2706x72695" "432.261.1842x958"
#> [4] "1-510-898-4317" "637-657-5120x1180" "970-413-5231x04013"
#> [7] "+99(3)9365555968" "858.518.8972" "449-824-5320"
#> [10] "809-959-3228x22460"
ch_job()
#> [1] "Engineer, chemical"
ch_job(10)
#> [1] "Multimedia specialist" "Marketing executive"
#> [3] "TEFL teacher" "Clinical molecular geneticist"
#> [5] "Surveyor, mining" "Engineer, water"
#> [7] "Warden/ranger" "Theatre manager"
#> [9] "Geochemist" "Programmer, systems"
ch_credit_card_provider()
#> [1] "JCB 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "Voyager" "Voyager" "Maestro" "VISA 13 digit"
ch_credit_card_number()
#> [1] "6011898962312431998"
ch_credit_card_number(n = 10)
#> [1] "4838754316845" "4506598649917" "54321906931129530"
#> [4] "3736315271564585" "3007277329293366" "6011477512197019225"
#> [7] "869970814530301513" "3088373617931330880" "3010620719899192"
#> [10] "4082160534002"
ch_credit_card_security_code()
#> [1] "254"
ch_credit_card_security_code(10)
#> [1] "769" "252" "839" "3837" "599" "717" "180" "403" "241" "057"
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] "Alma Hickle" NA NA NA NA
#> [6] NA NA NA NA NA
testVector$make_missing(x = ch_integer(10))
#> [1] NA NA NA NA 658 NA NA 413 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.