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] "Meteorologist"
x$name()
#> [1] "Mr. Mitch Trantow"
x$job()
#> [1] "Biochemist, clinical"
x$color_name()
#> [1] "Plum"

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] "Chemical engineer"                  "Public relations account executive"
#> [3] "Therapist, music"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Ouvrier paysagiste"                "Gérant de restauration collective"
#> [3] "Anesthésiste-réanimateur"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Diplomirani knjižničar" "Soboslikar – ličilac"   "Lovac"
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] "Blue"           "SeaGreen"       "LightSlateGray"
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 Guy Little V         Armed forces training and education officer 974.429.793…
#>  2 Mr. Spenser Windler  Lexicographer                               192-373-567…
#>  3 Darry Lueilwitz      Operations geologist                        +16(4)21245…
#>  4 Evans Barrows        Higher education careers adviser            012.126.030…
#>  5 Dr. Fernand Rath DDS Broadcast journalist                        370-543-550…
#>  6 Forest Zemlak II     Broadcast journalist                        392-377-312…
#>  7 Council Carroll PhD  Customer service manager                    1-081-822-3…
#>  8 Dr. Virgia Rowe      Chief Technology Officer                    +59(2)68756…
#>  9 Nicola Kassulke      Tax adviser                                 741-557-237…
#> 10 Ossie Kshlerin       Call centre manager                         03098581502
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                                   phone_number       
#>    <chr>                                 <chr>              
#>  1 Local government officer              100-796-7797x1785  
#>  2 Emergency planning/management officer 1-764-919-4533     
#>  3 Technical sales engineer              1-673-370-8862x4068
#>  4 Immunologist                          (268)167-6044      
#>  5 Senior tax professional/tax inspector 624-667-6191x1422  
#>  6 Hospital pharmacist                   835.264.7592x35671 
#>  7 Applications developer                322-000-1136x27693 
#>  8 Estate manager/land agent             189.927.1026x5775  
#>  9 Designer, blown glass/stained glass   451.589.4590       
#> 10 Insurance risk surveyor               209-115-7153       
#> # ℹ 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] "Burnice Gaylord"
ch_name(10)
#>  [1] "Ramon Vandervort-Waters" "Norwood Rath DDS"       
#>  [3] "Shannon Hettinger"       "Sharla Moen"            
#>  [5] "Lorne Murray"            "Milan Gutmann"          
#>  [7] "Miss Roberta O'Kon"      "Kanye Zemlak"           
#>  [9] "Deforest Terry"          "Miss Valentina Mann DVM"

phone number

ch_phone_number()
#> [1] "1-401-712-5886"
ch_phone_number(10)
#>  [1] "1-306-046-6368x923"  "173.353.2059"        "754.685.1795x4893"  
#>  [4] "1-198-132-1480x3956" "(376)383-4602"       "752-430-1312"       
#>  [7] "1-085-351-2717x9841" "713-720-0470"        "+62(1)8627649405"   
#> [10] "(286)397-9137x30839"

job

ch_job()
#> [1] "Commercial horticulturist"
ch_job(10)
#>  [1] "Animal technologist"                 "Forest/woodland manager"            
#>  [3] "Exercise physiologist"               "Engineer, mining"                   
#>  [5] "Heritage manager"                    "Insurance claims handler"           
#>  [7] "Catering manager"                    "Regulatory affairs officer"         
#>  [9] "Operations geologist"                "Chartered public finance accountant"

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] "PLN" "PKR" "NZD"

credit cards

ch_credit_card_provider()
#> [1] "Voyager"
ch_credit_card_provider(n = 4)
#> [1] "VISA 16 digit" "Discover"      "JCB 16 digit"  "JCB 16 digit"
ch_credit_card_number()
#> [1] "4949197485139388"
ch_credit_card_number(n = 10)
#>  [1] "3741873179866919"    "869930100454362569"  "180084290788750327" 
#>  [4] "3415768235504706"    "675945444747013"     "3462588708215339"   
#>  [7] "180031516397099852"  "3021430662132677"    "869909979899441899" 
#> [10] "6011476338293952775"
ch_credit_card_security_code()
#> [1] "099"
ch_credit_card_security_code(10)
#>  [1] "872"  "904"  "6641" "397"  "519"  "540"  "784"  "371"  "221"  "652"

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] "Dr. Richie Mraz I"  NA                   NA                  
#>  [4] NA                   NA                   NA                  
#>  [7] "Nelly Hirthe"       "Lenora Heidenreich" NA                  
#> [10] NA

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.