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] "Energy engineer"
x$name()
#> [1] "Amin Russel Sr."
x$job()
#> [1] "Sound technician, broadcasting/film/video"
x$color_name()
#> [1] "MediumSpringGreen"

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] "Hotel manager"             "Music therapist"          
#> [3] "Education officer, museum"
ch_job(locale = "fr_FR", n = 3)
#> [1] " ingénieur" "Mixeur"     "Teinturier"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Ovlašteni revident iz zaštite od požara"            
#> [2] "Stručni suradnik u školskoj ustanovi"               
#> [3] "Vodoinstalater, instalater grijanja i klimatizacije"
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] "Tan"         "LightBlue"   "DarkMagenta"
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 Debi Mueller             Solicitor, Scotland              1-215-978-3361x119 
#>  2 Ancil Runte              Therapist, sports                184.173.7710x713   
#>  3 Fulton Toy               Engineer, chemical               +91(8)4692434972   
#>  4 Caleigh Leuschke         Geoscientist                     1-673-383-7934x943 
#>  5 Hermann Fadel            Surveyor, quantity               (859)698-1550x93140
#>  6 Dr. Walt Raynor          Licensed conveyancer             +68(2)2218638928   
#>  7 Mrs. Clydie Yost         Marine scientist                 130-454-3742       
#>  8 Burnett Mraz             Fitness centre manager           263.822.2920x8980  
#>  9 Dr. Arlene Gleichner PhD Armed forces operational officer 01910638898        
#> 10 Judd Swift               Clinical psychologist            1-220-566-0718x112
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                                         phone_number        
#>    <chr>                                       <chr>               
#>  1 Health promotion specialist                 1-919-436-4596      
#>  2 Aeronautical engineer                       1-338-649-1584x9235 
#>  3 Engineer, civil (contracting)               129-389-1562        
#>  4 Structural engineer                         871-898-9066x842    
#>  5 Marine scientist                            1-342-997-9714x92099
#>  6 Diagnostic radiographer                     +37(4)4535157458    
#>  7 Psychologist, prison and probation services (175)333-3028x472   
#>  8 Product designer                            (822)312-4661x46355 
#>  9 Multimedia programmer                       235.839.6486        
#> 10 Colour technologist                         397.957.8457x3348   
#> # ℹ 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] "Jessee Auer"
ch_name(10)
#>  [1] "Mandie Reichel"          "Verona Haag-Rosenbaum"  
#>  [3] "Woodrow Pollich"         "Mr. Tolbert Steuber DVM"
#>  [5] "Laurette Nicolas-Turner" "Dr. Braeden Abbott MD"  
#>  [7] "Ethyl Yost"              "Lonie Roob I"           
#>  [9] "Lana Walker"             "Romie Little"

phone number

ch_phone_number()
#> [1] "1-068-989-4710x07512"
ch_phone_number(10)
#>  [1] "(799)496-9226"       "1-282-346-7920x1981" "1-575-730-2086x870" 
#>  [4] "410-911-6301"        "229.640.2364"        "(769)784-9748x8713" 
#>  [7] "380.728.6212x984"    "204.456.3069x8974"   "1-640-545-0758"     
#> [10] "(839)413-9384x8986"

job

ch_job()
#> [1] "English as a foreign language teacher"
ch_job(10)
#>  [1] "Music therapist"      "Musician"             "Optometrist"         
#>  [4] "Radio producer"       "Surveyor, minerals"   "Dentist"             
#>  [7] "Futures trader"       "Copy"                 "Engineer, automotive"
#> [10] "Engineer, production"

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] "SYP" "MOP" "AMD"

credit cards

ch_credit_card_provider()
#> [1] "VISA 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "JCB 16 digit"  "Maestro"       "VISA 16 digit" "JCB 16 digit"
ch_credit_card_number()
#> [1] "3755257755243847"
ch_credit_card_number(n = 10)
#>  [1] "869961957306677649"  "4987450895069270"    "589389640103092"    
#>  [4] "4780591491162107"    "3024766010054882"    "3011048519048597"   
#>  [7] "3096348472007295068" "3112715624182563430" "6011450908700808230"
#> [10] "210052467212960866"
ch_credit_card_security_code()
#> [1] "5211"
ch_credit_card_security_code(10)
#>  [1] "789"  "917"  "100"  "509"  "167"  "437"  "991"  "326"  "972"  "6019"

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                             "Stetson Dicki Jr."           
#>  [3] NA                             NA                            
#>  [5] NA                             NA                            
#>  [7] "Jeraldine Cassin-Oberbrunner" NA                            
#>  [9] "Dr. Festus Beahan PhD"        "Jedediah Kuhic MD"

numeric data

testVector$make_missing(x = ch_integer(10))
#>  [1]  NA  NA  NA  NA  NA  NA  NA 627  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.