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] "Therapist, music"
x$name()
#> [1] "Edra Orn"
x$job()
#> [1] "Engineer, petroleum"
x$color_name()
#> [1] "Teal"

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] "Therapist, sports"     "Glass blower/designer" "Public house manager"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Cadreur"               "Facteur d'instruments" "Architecte"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Stalni sudski procjenitelj" "Graditelj orgulja"         
#> [3] "Glazbalar"
ch_job(locale = "uk_UA", n = 3)
#> [1] "Електротехнік" "Астронавт"     "Актор"
ch_job(locale = "zh_TW", n = 3)
#> [1] "金融理財專員"     "太陽能技術工程師" "IC佈局工程師"

For colors:

ch_color_name(locale = "en_US", n = 3)
#> [1] "DarkOrchid"     "PaleTurquoise"  "DarkOliveGreen"
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 Shanta Altenwerth PhD  Librarian, public     253-282-4167        
#>  2 Linna Mosciski         Stage manager         (890)748-0606x52148 
#>  3 Casimir Kilback-Boyle  Operations geologist  1-253-601-2337x27724
#>  4 Lavonia Hirthe DVM     Camera operator       933-861-9484        
#>  5 Jenni Hackett          Forensic psychologist 666-336-7014x95760  
#>  6 Bethel Leffler-Collier Careers adviser       +40(3)5926458216    
#>  7 Banks Gleason          Media planner         04289498507         
#>  8 Kayli Hermiston        Meteorologist         113.761.8107        
#>  9 Lawanda Corkery        Soil scientist        (537)105-7919x1403  
#> 10 Ryder Greenholt        Nurse, mental health  04910977147
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                                 phone_number      
#>    <chr>                               <chr>             
#>  1 Biomedical engineer                 1-528-531-8694    
#>  2 Chemist, analytical                 09373575493       
#>  3 Scientist, research (life sciences) 917-860-6130x61113
#>  4 Telecommunications researcher       1-557-112-2094    
#>  5 Engineer, maintenance (IT)          1-350-397-6380x324
#>  6 Biomedical scientist                +40(9)0137329683  
#>  7 Engineer, civil (consulting)        500.203.9962x54232
#>  8 Research scientist (life sciences)  068-230-9465x9492 
#>  9 Interpreter                         672-319-3145x49990
#> 10 Maintenance engineer                (746)095-3179x6709
#> # ℹ 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] "Ms. Carra Kilback"
ch_name(10)
#>  [1] "Luca Beatty V"           "Tomeka Monahan"         
#>  [3] "Susanna Hartmann-Green"  "Manila Schultz"         
#>  [5] "Lillard Ferry"           "Mr. Arthor Rutherford I"
#>  [7] "Florine Schimmel"        "Jenelle Turcotte-Harvey"
#>  [9] "Silver Boyle"            "Hildur Schuster"

phone number

ch_phone_number()
#> [1] "05777431923"
ch_phone_number(10)
#>  [1] "108-935-8661x657"     "849.533.6767x273"     "946.250.7381"        
#>  [4] "183.291.4838"         "1-327-503-8837x35740" "+72(8)1960669972"    
#>  [7] "(955)855-7547"        "413.055.3791x993"     "(063)931-2647x41792" 
#> [10] "(731)928-5559"

job

ch_job()
#> [1] "Learning disability nurse"
ch_job(10)
#>  [1] "Editor, magazine features"    "Insurance account manager"   
#>  [3] "Scientist, forensic"          "Ceramics designer"           
#>  [5] "Trading standards officer"    "Garment/textile technologist"
#>  [7] "Curator"                      "Engineer, agricultural"      
#>  [9] "Land"                         "Engineer, automotive"

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] "IMP" "ERN" "WST"

credit cards

ch_credit_card_provider()
#> [1] "Diners Club / Carte Blanche"
ch_credit_card_provider(n = 4)
#> [1] "Discover"                    "Mastercard"                 
#> [3] "Diners Club / Carte Blanche" "JCB 16 digit"
ch_credit_card_number()
#> [1] "630462687562298"
ch_credit_card_number(n = 10)
#>  [1] "869946279664105588"  "869975290417544472"  "3528674184111128952"
#>  [4] "52349577122947812"   "3484611190424492"    "4127974590917138"   
#>  [7] "3023727680726002"    "869921608454543823"  "501819489890467"    
#> [10] "4290120916850121"
ch_credit_card_security_code()
#> [1] "444"
ch_credit_card_security_code(10)
#>  [1] "293"  "729"  "140"  "419"  "4146" "212"  "696"  "432"  "280"  "024"

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] "Gay Heidenreich"         "Dr. Sing Herzog Sr."    
#>  [3] NA                        "Kamila Hane"            
#>  [5] "Jeb Feeney"              "Renaldo Quitzon-Corkery"
#>  [7] "Addyson Raynor"          NA                       
#>  [9] "Leona Heidenreich-Veum"  "Tim Medhurst"

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.