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] "Publishing rights manager"
x$name()
#> [1] "Zula Kling"
x$job()
#> [1] "Ranger/warden"
x$color_name()
#> [1] "RoyalBlue"

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] "Financial adviser"  "Field seismologist" "Legal executive"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Chirurgien"                            
#> [2] "Chef de publicité"                     
#> [3] "Conseiller en salle de remise en forme"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Odgojitelj djece predškolske dobi" "Zaštitar-tehničar"                
#> [3] "Porezni savjetnik"
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] "DeepPink"   "MistyRose"  "MediumBlue"
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 Toshiko O'Kon DVM       Engineer, petroleum                  1-699-754-3186  
#>  2 Alois Hills             Retail banker                        905-415-3805x05…
#>  3 Kamya Leuschke          Careers information officer          264-120-5089    
#>  4 Marvin Kemmer-Gulgowski Science writer                       (863)445-9146x1…
#>  5 Catharine Bradtke       Lobbyist                             (167)312-1391   
#>  6 Amey Gleason            Lecturer, higher education           1-514-157-2106x…
#>  7 Julia Oberbrunner       Accountant, chartered public finance 1-501-220-0082  
#>  8 Maxine Goyette-Waelchi  Designer, textile                    03843116891     
#>  9 Thor Jaskolski          Engineer, manufacturing systems      969-810-9708x349
#> 10 Alexia Sipes-Konopelski Waste management officer             1-493-764-0853x…
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                           phone_number      
#>    <chr>                         <chr>             
#>  1 Chief Strategy Officer        205-756-4831x604  
#>  2 Psychologist, counselling     (165)930-8240     
#>  3 Economist                     748.035.7230x29191
#>  4 Health and safety adviser     00516017040       
#>  5 Engineer, water               07507039843       
#>  6 Research officer, trade union +54(2)1428494887  
#>  7 Radio broadcast assistant     (729)881-6342     
#>  8 Engineer, maintenance (IT)    217.329.5134      
#>  9 Legal secretary               (992)481-4572     
#> 10 Land                          02426130985       
#> # ℹ 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] "Florance Feeney"
ch_name(10)
#>  [1] "Karim Bednar"            "Mrs. Florance Herman"   
#>  [3] "Declan Keeling"          "Dr. Edmund Fritsch"     
#>  [5] "Dr. Barnett Kuvalis MD"  "Freddie Gaylord-Friesen"
#>  [7] "Jerry Franecki"          "Phylicia Wiza"          
#>  [9] "Joelle Walker"           "Miss Kelsie Hilll DVM"

phone number

ch_phone_number()
#> [1] "601-716-2393"
ch_phone_number(10)
#>  [1] "1-664-390-8730x940"  "970-637-5216"        "(420)395-0643x136"  
#>  [4] "610-102-7677x3804"   "(114)238-9596"       "(065)014-2635x409"  
#>  [7] "1-538-052-3733x5855" "100-852-4206x773"    "01222823401"        
#> [10] "+28(0)7246942818"

job

ch_job()
#> [1] "Development worker, community"
ch_job(10)
#>  [1] "Industrial/product designer"       "Information systems manager"      
#>  [3] "Librarian, public"                 "Therapist, drama"                 
#>  [5] "Patent examiner"                   "Financial risk analyst"           
#>  [7] "Regulatory affairs officer"        "Academic librarian"               
#>  [9] "Planning and development surveyor" "Water engineer"

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] "MYR" "ISK" "ERN"

credit cards

ch_credit_card_provider()
#> [1] "VISA 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "VISA 16 digit"    "American Express" "Voyager"          "JCB 15 digit"
ch_credit_card_number()
#> [1] "4579536890225505"
ch_credit_card_number(n = 10)
#>  [1] "4420795827662823"   "4727976885291461"   "4509747758252615"  
#>  [4] "3761891854105523"   "060438406142141"    "54087544853021627" 
#>  [7] "675940667317172"    "869990560888749011" "676374727478518"   
#> [10] "4001021872950295"
ch_credit_card_security_code()
#> [1] "046"
ch_credit_card_security_code(10)
#>  [1] "545"  "415"  "114"  "166"  "447"  "095"  "4884" "767"  "399"  "903"

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] "Breanna Wilkinson"        "Lucie Lang"              
#>  [3] "Lovey Beatty"             "Ms. Josefita Denesik PhD"
#>  [5] NA                         "Ima Weissnat"            
#>  [7] "Miss Rae Grant"           "Laurence Homenick"       
#>  [9] "Helma Cummings"           "Westin DuBuque"

numeric data

testVector$make_missing(x = ch_integer(10))
#>  [1] 702  36 690 849 830 158  NA  21 682 327

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.