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] "Animal nutritionist"
x$name()
#> [1] "Dione Kub"
x$job()
#> [1] "Television production assistant"
x$color_name()
#> [1] "LightPink"

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] "Oceanographer"       "Insurance broker"    "Chemist, analytical"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Domoticien"                  "Dresseur d'animaux"         
#> [3] "Chef de projet informatique"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Ovlašteni inženjer geodezije" "Ljekarnik specijalist"       
#> [3] "Stalni sudski tumač"
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] "MidnightBlue" "OliveDrab"    "FireBrick"
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 Tressie Gulgowski-McKenzie Journalist, broadcasting     1-147-811-1108    
#>  2 Julien Hintz               Computer games developer     981-336-2929x19670
#>  3 Dr. Cristal Koch MD        Dentist                      1-811-482-6011    
#>  4 Eunice Swift PhD           Risk manager                 453-968-1383x02275
#>  5 Gee Kozey                  Designer, graphic            (130)034-1081x2228
#>  6 Miss Demetria Leuschke     Quantity surveyor            1-249-874-9472    
#>  7 Remy Kozey                 Travel agency manager        351.555.1759x0006 
#>  8 Margret Bosco              Research scientist (medical) (495)839-6403     
#>  9 Dr. Vincent Reinger IV     Industrial/product designer  +46(2)8003548908  
#> 10 Arvin Cremin               Engineer, maintenance (IT)   (441)830-8455x2079
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                       phone_number        
#>    <chr>                     <chr>               
#>  1 Herpetologist             986-012-1932        
#>  2 Electronics engineer      1-843-793-7132      
#>  3 Broadcast engineer        1-925-485-2912x90840
#>  4 Child psychotherapist     02960262109         
#>  5 Legal executive           358.255.9104        
#>  6 Textile designer          890.075.4529x83000  
#>  7 Forensic scientist        564.997.4955x3020   
#>  8 Estate manager/land agent (007)696-2061x3684  
#>  9 Therapist, occupational   1-827-877-6931x049  
#> 10 Learning mentor           (359)737-6757x5223  
#> # ℹ 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] "Karim O'Reilly"
ch_name(10)
#>  [1] "Shae Armstrong"             "Dr. Floretta DuBuque PhD"  
#>  [3] "Ms. Trilby O'Reilly"        "Pat Lueilwitz"             
#>  [5] "Hulda Fisher"               "Elsa Bartoletti-Macejkovic"
#>  [7] "Devan Bogan"                "French Kris"               
#>  [9] "Roxanna Cole"               "Camden Oberbrunner I"

phone number

ch_phone_number()
#> [1] "001-333-6482"
ch_phone_number(10)
#>  [1] "04573867315"          "+91(2)0186752198"     "+60(9)7657212080"    
#>  [4] "489.716.0479x32047"   "1-166-473-7782x02837" "038-934-2929"        
#>  [7] "(513)313-6860x9229"   "(571)190-8737x657"    "831.859.9666x941"    
#> [10] "629.389.3917"

job

ch_job()
#> [1] "Midwife"
ch_job(10)
#>  [1] "Surveyor, rural practice"        "Charity officer"                
#>  [3] "Police officer"                  "Editor, magazine features"      
#>  [5] "Environmental education officer" "Insurance broker"               
#>  [7] "Computer games developer"        "Musician"                       
#>  [9] "Ecologist"                       "Financial trader"

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] "BZD" "TVD" "SPL"

credit cards

ch_credit_card_provider()
#> [1] "Diners Club / Carte Blanche"
ch_credit_card_provider(n = 4)
#> [1] "American Express"            "Discover"                   
#> [3] "Diners Club / Carte Blanche" "Discover"
ch_credit_card_number()
#> [1] "4618086748539"
ch_credit_card_number(n = 10)
#>  [1] "869911822314644646"  "4767067007934"       "3096528924659292498"
#>  [4] "4607042476808240"    "4237213515768"       "6011047979000591933"
#>  [7] "4221304132701177"    "502055290909575"     "3053079397154320"   
#> [10] "6011521295484539198"
ch_credit_card_security_code()
#> [1] "378"
ch_credit_card_security_code(10)
#>  [1] "609" "643" "707" "803" "014" "346" "401" "140" "020" "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                         "Miss Henriette Tremblay" 
#>  [3] "Malia Legros-Bednar"      "Ms. Jailene Haley"       
#>  [5] "Sherrill Schimmel DDS"    "Burk Hills"              
#>  [7] "Hailie Jakubowski-Heaney" "Brandin Schmitt"         
#>  [9] "Michial Hahn-Reilly"      NA

numeric data

testVector$make_missing(x = ch_integer(10))
#>  [1]  NA  NA 791 957  NA 889  38 742  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.