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] "Psychologist, occupational"
x$name()
#> [1] "Candyce Thiel"
x$job()
#> [1] "Fast food restaurant manager"
x$color_name()
#> [1] "Snow"

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] "Insurance risk surveyor"      "Teacher, early years/pre"    
#> [3] "Community development worker"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Menuisier"                         "Gérant de restauration collective"
#> [3] "Chirurgien-dentiste"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Primalja"                   "Prvostupnik fizioterapije" 
#> [3] "Konzervator –  restaurator"
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] "MediumOrchid" "Khaki"        "Blue"
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 Westley Pollich         Psychologist, clinical         208.679.2974       
#>  2 Tom Larkin              Engineer, land                 (854)282-0700x1366 
#>  3 Hardin Beahan DDS       Quality manager                789-184-0270       
#>  4 Rashaad Effertz         Community arts worker          100.498.6495x00456 
#>  5 Maximiliano Kovacek Sr. Designer, exhibition/display   1-046-842-0680     
#>  6 Bryon Nolan             Audiological scientist         1-490-347-0303x6084
#>  7 Mr. Nolan Bechtelar     Forensic psychologist          (459)250-3938x8860 
#>  8 Avery Yost I            Politician's assistant         242.964.5648x92623 
#>  9 Renita Rippin           Tree surgeon                   902.034.0643x11761 
#> 10 Burnice Toy-Buckridge   Equality and diversity officer 783-198-5506
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                              phone_number        
#>    <chr>                            <chr>               
#>  1 Doctor, general practice         406-952-4596        
#>  2 Cabin crew                       078.910.2712x8520   
#>  3 Chartered management accountant  709-688-0203x2116   
#>  4 Radio producer                   +51(2)8945388526    
#>  5 Administrator, arts              1-286-621-0120x61962
#>  6 Higher education careers adviser 991-037-3207        
#>  7 Occupational psychologist        167.242.4173x440    
#>  8 Loss adjuster, chartered         08872770841         
#>  9 Occupational hygienist           1-232-700-5190      
#> 10 Tax adviser                      1-792-365-1233x6729 
#> # ℹ 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] "Dr. Dominic Turcotte"
ch_name(10)
#>  [1] "Karrie Walsh"        "Alesia Franecki"     "Polk Cormier"       
#>  [4] "Ramsey Doyle-Lowe"   "Dr. Connor Gottlieb" "Dr. Leesa Stehr"    
#>  [7] "Merlyn Hauck"        "Yadiel Walker DVM"   "Dr. Gidget Braun MD"
#> [10] "Clive Kiehn-Beier"

phone number

ch_phone_number()
#> [1] "03195299521"
ch_phone_number(10)
#>  [1] "1-317-663-6705"       "988-134-9523x71912"   "730.720.0289"        
#>  [4] "(165)977-6529"        "(806)322-3142x9213"   "526.251.2908"        
#>  [7] "124-433-2351x585"     "1-258-276-5110x26553" "1-706-342-2268"      
#> [10] "199.396.1879x691"

job

ch_job()
#> [1] "Minerals surveyor"
ch_job(10)
#>  [1] "Claims inspector/assessor"      "Trading standards officer"     
#>  [3] "Engineer, aeronautical"         "Chief Financial Officer"       
#>  [5] "Careers adviser"                "Mechanical engineer"           
#>  [7] "Records manager"                "Investment banker, operational"
#>  [9] "Chiropodist"                    "Editor, magazine features"

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] "IRR" "NGN" "MKD"

credit cards

ch_credit_card_provider()
#> [1] "Diners Club / Carte Blanche"
ch_credit_card_provider(n = 4)
#> [1] "VISA 16 digit" "VISA 16 digit" "JCB 16 digit"  "JCB 15 digit"
ch_credit_card_number()
#> [1] "3337193158438487699"
ch_credit_card_number(n = 10)
#>  [1] "561201802434074"     "6011707993242365734" "6011980331990694047"
#>  [4] "52490154386917571"   "676264759565480"     "52894055163724613"  
#>  [7] "4545242893489"       "4558005690026"       "55351990263099423"  
#> [10] "3158704582007564343"
ch_credit_card_security_code()
#> [1] "011"
ch_credit_card_security_code(10)
#>  [1] "358"  "367"  "489"  "3533" "265"  "357"  "174"  "700"  "254"  "068"

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                         
#>  [3] NA                          NA                         
#>  [5] "Miss Sudie Greenfelder MD" "Tim Greenfelder"          
#>  [7] NA                          "Roosevelt Rodriguez"      
#>  [9] NA                          "Briana Emard-Rau"

numeric data

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

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.