Introduction to the charlatan package

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:

  • Students in a classroom setting learning any task that needs a dataset.
  • People doing simulations/modeling that need some fake data
  • Generate fake dataset of users for a database before actual users exist
  • Complete missing spots in a dataset
  • Generate fake data to replace sensitive real data with before public release
  • Create a random set of colors for visualization
  • Generate random coordinates for a map
  • Get a set of randomly generated DOIs (Digital Object Identifiers) to assign to fake scholarly artifacts
  • Generate fake taxonomic names for a biological dataset
  • Get a set of fake sequences to use to test code/software that uses sequence data

See the Creating realistic data vignette for a few realistic examples.

Contributing

See the Contributing to charlatan vignette.

Package API

  • Low level interfaces: All of these are R6 objects that a user can initialize and then call methods on. These contain all the logic that the below interfaces use.
  • High level interfaces: There are high level functions prefixed with 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 above

Install

Stable version from CRAN

install.packages("charlatan")

Development version from Github

remotes::install_github("ropensci/charlatan")
library("charlatan")

high level function

… for all fake data operations

x <- fraudster()
x$job()
#> [1] "Education officer, community"
x$name()
#> [1] "Kacy Hegmann"
x$job()
#> [1] "Chief Marketing Officer"
x$color_name()
#> [1] "Magenta"

locale support

Here we create 3 jobs, for different locales:

  • English USA
  • French, France
  • Croatian, Croatia
  • Ukrainian, Ukraine
  • Chinese, Taiwan
ch_job(locale = "en_US", n = 3)
#> [1] "Orthoptist"                        "Radiation protection practitioner"
#> [3] "Air traffic controller"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Correcteur"              "Marchandiseur"          
#> [3] "Animateur du patrimoine"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Inženjer medicinsko- laboratorijske dijagnostike"
#> [2] "Pediker"                                         
#> [3] "Klesar"
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] "MediumSlateBlue" "LightCoral"      "Peru"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Яскраво-бурштиновий" "Арсеновий"           "Гірчичний"

generate a dataset

ch_generate()
#> # A tibble: 10 × 3
#>    name                     job                                    phone_number 
#>    <chr>                    <chr>                                  <chr>        
#>  1 Miss Kenisha Gerlach DDS Fitness centre manager                 (731)690-1007
#>  2 Mr. Ryan Stark           Advertising art director               (961)576-2588
#>  3 Marlin Blick Jr.         Financial manager                      06891721535  
#>  4 Alysa Zemlak             Charity fundraiser                     662-940-0365…
#>  5 Pheobe Bailey            Human resources officer                (583)307-1138
#>  6 Cosmo Hane II            Conservator, museum/gallery            (887)374-172…
#>  7 Leala Borer-Schmidt      Legal secretary                        1-397-616-28…
#>  8 Martin Schroeder         Teacher, English as a foreign language 01356903787  
#>  9 Efrain Volkman           Television production assistant        548-642-9237 
#> 10 Vassie Simonis           Proofreader                            381-472-2228…
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                                               phone_number      
#>    <chr>                                             <chr>             
#>  1 Architect                                         (563)102-8351     
#>  2 Records manager                                   (763)209-6878x751 
#>  3 Health and safety inspector                       1-263-619-9796    
#>  4 Broadcast engineer                                205-578-5336x6323 
#>  5 Computer games developer                          544-922-1821x00578
#>  6 Historic buildings inspector/conservation officer 645.389.3371      
#>  7 Legal secretary                                   248-360-3297      
#>  8 Homeopath                                         950.222.7634      
#>  9 Careers information officer                       520.142.1542x57552
#> 10 Set designer                                      703.337.5466      
#> # ℹ 20 more rows

Data types, localized

We can create locale specific versions of:

  • Colors
  • Companies
  • Elements (of the periodic table)
  • Files
  • Internet
  • Jobs
  • Lorem
  • Persons
  • Phone numbers
  • Social Security Numbers
  • Taxonomies
  • UserAgent

Examples:

person name

ch_name()
#> [1] "Dola Raynor"
ch_name(10)
#>  [1] "Miss Bobbi Cole MD"          "Evangelina Leannon"         
#>  [3] "Magdalene Considine-McGlynn" "Versie Frami-Miller"        
#>  [5] "Paisley Berge"               "Manley Kozey"               
#>  [7] "Bernardo Paucek"             "Woodrow Ward Sr."           
#>  [9] "Kennedy Jaskolski"           "Jake Cummerata"

phone number

ch_phone_number()
#> [1] "665.542.8502x6165"
ch_phone_number(10)
#>  [1] "912.052.3280"       "261.756.2313"       "495.305.3795x74006"
#>  [4] "1-664-895-9171"     "(760)839-0839"      "842.012.2113x8659" 
#>  [7] "1-257-284-9725"     "02968485357"        "799.654.2060"      
#> [10] "(615)739-9171x5147"

job

ch_job()
#> [1] "Oceanographer"
ch_job(10)
#>  [1] "Water engineer"                       
#>  [2] "Human resources officer"              
#>  [3] "Actuary"                              
#>  [4] "Chief Operating Officer"              
#>  [5] "Radiographer, therapeutic"            
#>  [6] "Theatre director"                     
#>  [7] "Proofreader"                          
#>  [8] "Warehouse manager"                    
#>  [9] "Loss adjuster, chartered"             
#> [10] "Senior tax professional/tax inspector"

Data types, universal

Some data types are not localized (arguably the files and user_agents, are mostly universal too).

  • Currency
  • credit card
  • Sequence (DNA)
  • Numerics (doubles, integers, numbers from a distribution; uniform, normal, log-normal, and beta)
  • Miscellaneous (booleans, language codes)
  • DOIs (Digital Object Identifiers, used in scientific journals)
  • Coordinates (GPS coordinates)

currency

ch_currency(3)
#> [1] "AWG" "BBD" "MXN"

credit cards

ch_credit_card_provider()
#> [1] "JCB 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "Maestro"       "JCB 16 digit"  "VISA 16 digit" "VISA 16 digit"
ch_credit_card_number()
#> [1] "210009207281960171"
ch_credit_card_number(n = 10)
#>  [1] "3019097971651499"    "060432462755771"     "180066257063321407" 
#>  [4] "3481636940315743"    "180084457151770469"  "52171361685007592"  
#>  [7] "4403736025753247"    "3439503206201376"    "3762985255652254"   
#> [10] "6011690611522459568"
ch_credit_card_security_code()
#> [1] "703"
ch_credit_card_security_code(10)
#>  [1] "492" "100" "603" "183" "683" "952" "644" "210" "569" "091"

Missing data

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()

character strings

testVector$make_missing(x = ch_generate()$name)
#>  [1] NA                    NA                    NA                   
#>  [4] "Davian Abernathy"    "Iyana DuBuque PhD"   "Joycelyn Ullrich MD"
#>  [7] NA                    NA                    NA                   
#> [10] "Anona Waelchi"

numeric data

testVector$make_missing(x = ch_integer(10))
#>  [1]  NA  NA 309  NA  NA  NA  NA 222  NA 984

logicals

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

Messy data

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.