charlatan
makes realistic looking fake data, inspired
from and borrowing some code from Python’s faker
Why would you want to make fake data that looks real? Here’s some possible use cases to give you a sense for what you can do with this package:
See the Creating realistic data vignette for a few realistic examples.
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
remotes::install_github("ropensci/charlatan")
library("charlatan")
… for all fake data operations
x <- fraudster()
x$job()
#> [1] "Insurance underwriter"
x$name()
#> [1] "Dr. Ezekiel Legros Sr."
x$job()
#> [1] "Insurance account manager"
x$color_name()
#> [1] "Brown"
Here we create 3 jobs, for different locales:
ch_job(locale = "en_US", n = 3)
#> [1] "Armed forces logistics/support/administrative officer"
#> [2] "Drilling engineer"
#> [3] "Publishing copy"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Opérateur de fabrication de produits alimentaires"
#> [2] "Technicien"
#> [3] "Aquaculteur"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Fotograf"
#> [2] "Voditelj skele u nacionalnoj plovidbi"
#> [3] "Autolimar"
ch_job(locale = "uk_UA", n = 3)
#> [1] "Історик" "Водій" "Машиніст"
ch_job(locale = "zh_TW", n = 3)
#> [1] "MIS程式設計師" "美療/芳療師" "資訊專業人員"
For colors:
ch_color_name(locale = "en_US", n = 3)
#> [1] "LightSlateGray" "HotPink" "ForestGreen"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Ніжно-рожевий" "Зелена мʼята" "Ультрамариновий"
ch_generate()
#> # A tibble: 10 × 3
#> name job phone_number
#> <chr> <chr> <chr>
#> 1 Efrem Stanton Jr. Doctor, general practice (454)196-5832x66841
#> 2 Griffin Parker Advertising art director 1-989-227-1920
#> 3 Dr. Braiden Goyette IV Podiatrist 684.092.5429x82726
#> 4 Werner Kunze II Fine artist 1-158-569-6973x733
#> 5 Ms. Ilene Hahn Community education officer 1-915-862-0841x315
#> 6 Aden Bogisich V Surveyor, building 539.749.0954x640
#> 7 Chloie Jacobs Geoscientist 025.820.2209
#> 8 Lora Rau Journalist, newspaper 1-699-957-4876x4502
#> 9 Hansford Considine Automotive engineer 772-137-1301x8642
#> 10 Rollo Funk-Huels Buyer, industrial (948)351-0795
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#> job phone_number
#> <chr> <chr>
#> 1 Scientist, research (maths) 1-085-954-9265x8014
#> 2 Bonds trader (794)555-0796x10850
#> 3 Podiatrist 1-438-002-4183x507
#> 4 Clinical molecular geneticist 571-591-7262x12589
#> 5 Community pharmacist 586.341.7788x11515
#> 6 Health physicist +72(4)0814084813
#> 7 Leisure centre manager (150)330-9293x3906
#> 8 Records manager 00789139342
#> 9 Fine artist 1-821-077-1712
#> 10 Naval architect +39(1)8754217625
#> # ℹ 20 more rows
We can create locale specific versions of:
Examples:
ch_name()
#> [1] "Dr. Finn Bechtelar II"
ch_name(10)
#> [1] "Aiyana Casper" "Dr. Brendan Rodriguez DVM"
#> [3] "Peggy Swift" "Jerrilyn Powlowski"
#> [5] "Dr. Bryant Abernathy IV" "Little Lynch"
#> [7] "Beula Okuneva" "Francisquita Botsford"
#> [9] "Dr. Venie Reynolds" "Candyce Terry MD"
ch_phone_number()
#> [1] "(402)943-8800"
ch_phone_number(10)
#> [1] "328-740-3974x4990" "(931)136-9980" "1-586-443-3402x7010"
#> [4] "03380022256" "1-410-964-9865" "(052)158-8081x18272"
#> [7] "(857)634-6468x918" "09030895069" "03608832325"
#> [10] "+06(3)9657584920"
ch_job()
#> [1] "Pharmacist, community"
ch_job(10)
#> [1] "Ophthalmologist" "Investment banker, operational"
#> [3] "Psychotherapist" "Civil engineer, consulting"
#> [5] "Engineer, building services" "Engineer, technical sales"
#> [7] "Biomedical engineer" "Surveyor, mining"
#> [9] "IT technical support officer" "Engineer, communications"
Some data types are not localized (arguably the files and user_agents, are mostly universal too).
ch_currency(3)
#> [1] "XDR" "JMD" "BRL"
ch_credit_card_provider()
#> [1] "American Express"
ch_credit_card_provider(n = 4)
#> [1] "VISA 16 digit" "JCB 16 digit" "Discover" "VISA 16 digit"
ch_credit_card_number()
#> [1] "4363933519243"
ch_credit_card_number(n = 10)
#> [1] "3756291952838413" "4025118825390439" "4593497363459778"
#> [4] "55862295532441014" "4348774484495404" "869971194735154226"
#> [7] "3438307179547067" "869999711314635339" "4007381069954052"
#> [10] "676288886680409"
ch_credit_card_security_code()
#> [1] "327"
ch_credit_card_security_code(10)
#> [1] "552" "881" "174" "795" "436" "9122" "705" "247" "1874" "322"
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] "Hobson Weimann-Ortiz" NA "Mercy Ward"
#> [4] "Miss Ethyle Klein DDS" NA "Dr. Dawson Huels Jr."
#> [7] "Jaycob Morar" "Trinidad Parker DVM" NA
#> [10] NA
testVector$make_missing(x = ch_integer(10))
#> [1] 596 NA 894 NA NA 532 736 NA NA 354
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 DDS"
#> [3] "Ms. Jada Lesch" "Inga Dach"
#> [5] "Keyshawn Schaefer" "Ferdinand Bergstrom"
#> [7] "Justen Simonis" "Ms. Doloris Stroman DVM"
#> [9] "Mrs. Ermine Heidenreich" "Marion Corwin"
#> [11] "Jalen Grimes" "Mr. Sullivan Hammes IV"
#> [13] "Adrien Vandervort-Dickens" "Dr. Sharif Kunde"
#> [15] "Marlena Reichert PhD" "Mr. Brandan Oberbrunner"
#> [17] "Lloyd Adams III" "Randy Ziemann"
#> [19] "Gina Sanford" "Cornell Funk"
#> [21] "Yadiel Collier" "Kamryn Johnson"
#> [23] "Tyesha Schmeler" "Ernie Hegmann-Graham"
#> [25] "Zackery Runolfsdottir" "Cleveland Predovic"
#> [27] "Melvyn Hickle" "Larry Nienow IV"
#> [29] "Vilma Rutherford" "Wiliam Ziemann-Fadel"
#> [31] "Mrs. Kathy Halvorson" "Mirtie Harvey-Shanahan"
#> [33] "Eliezer Pfeffer" "Dr. Shep Buckridge"
#> [35] "Kyree Kutch" "Ms. Delpha Grant"
#> [37] "Ms. Icie Crooks" "Loney Jenkins-Lindgren"
#> [39] "Shania Donnelly DVM" "Dr. Patric Veum"
#> [41] "Amirah Rippin DVM" "Randle Hilpert"
#> [43] "Soren Dare" "Roderic Walter"
#> [45] "Farah Daugherty MD" "Marva Crooks"
#> [47] "Ryland Ledner" "Girtha Harvey DDS"
#> [49] "Staci 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.