Skip to contents

charlatan makes fake data, inspired from and borrowing some code from Python’s faker

Why would you want to make fake data? 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 (Digial 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

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

devtools::install_github("ropensci/charlatan")

high level function

… for all fake data operations

x <- fraudster()
x$job()
#> [1] "Architect"
x$name()
#> [1] "Sandy Crist"
x$job()
#> [1] "Lexicographer"
x$color_name()
#> [1] "PaleGoldenRod"

locale support

Adding more locales through time, e.g.,

Locale support for job data

ch_job(locale = "en_US", n = 3)
#> [1] "Development worker, international aid"
#> [2] "Commissioning editor"                 
#> [3] "Mudlogger"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Chef de projet multimédia" "Bibliothécaire"           
#> [3] "Costumier"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Klobučar"                          "Ovlašteni inženjer elektrotehnike"
#> [3] "Pirotehničar"
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] "MintCream" "Beige"     "DarkGray"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Брунатний"          "Темно-зелений хакі" "Баклажановий"

More coming soon …

generate a dataset

ch_generate()
#> # A tibble: 10 × 3
#>    name                    job                                 phone_number     
#>    <chr>                   <chr>                               <chr>            
#>  1 Golden Little           Designer, interior/spatial          837-939-9134x1093
#>  2 Markus Sanford          Careers adviser                     +71(0)5832327883 
#>  3 Mr. Lashawn Rosenbaum   Tourist information centre manager  08455789224      
#>  4 Lincoln Roob            Chief Executive Officer             714-173-9105x009…
#>  5 Mr. Lenwood Sporer      Surveyor, minerals                  1-449-548-4957x7…
#>  6 Ms. Christy Kerluke DVM Therapist, horticultural            287-870-3151     
#>  7 Mr. Olaf Cronin         Engineer, broadcasting (operations) 914.716.1678     
#>  8 Harmon Schmeler         Designer, television/film set       429-545-6475x105 
#>  9 Ruthie Zboncak          Printmaker                          347-281-2220x901 
#> 10 Dr. Collins Kessler I   Clinical psychologist               (543)168-5322x452
ch_generate('job', 'phone_number', n = 30)
#> # A tibble: 30 × 2
#>    job                         phone_number       
#>    <chr>                       <chr>              
#>  1 Food technologist           03549417424        
#>  2 Land                        594.083.7845x05479 
#>  3 Designer, textile           1-432-476-3960     
#>  4 Psychologist, forensic      495-053-3395x3405  
#>  5 Operations geologist        1-548-032-5688x4989
#>  6 Production assistant, radio 033-524-9957x26216 
#>  7 Cabin crew                  265-310-2094x9029  
#>  8 Charity officer             +93(0)7299983246   
#>  9 Financial manager           965-594-3943x332   
#> 10 Claims inspector/assessor   +98(0)8843080704   
#> # ℹ 20 more rows

Data types

person name

ch_name()
#> [1] "Conner Schowalter-Windler"
ch_name(10)
#>  [1] "Mr. Hoke McGlynn"           "Dr. Antwain Bednar"        
#>  [3] "Eugenio Waters"             "Mr. Jarret Kohler"         
#>  [5] "Mrs. Cecelia Bergstrom DVM" "Glen Champlin I"           
#>  [7] "Gideon Cummings-Dicki"      "Maria Berge"               
#>  [9] "Maud Tremblay"              "Candi Franecki"

phone number

ch_phone_number()
#> [1] "743-358-3715x753"
ch_phone_number(10)
#>  [1] "137.507.4356"        "(626)227-1430"       "(501)635-2521x892"  
#>  [4] "118-694-7579x78747"  "406-969-7387x0247"   "1-870-253-0672"     
#>  [7] "1-313-837-2871x2276" "939.749.5530x3506"   "(797)713-2849x045"  
#> [10] "1-595-766-1731"

job

ch_job()
#> [1] "Sub"
ch_job(10)
#>  [1] "Air broker"                      "Music tutor"                    
#>  [3] "Television production assistant" "Computer games developer"       
#>  [5] "Psychologist, occupational"      "Health service manager"         
#>  [7] "Therapist, speech and language"  "Geochemist"                     
#>  [9] "Conservator, furniture"          "Manufacturing systems engineer"

credit cards

ch_credit_card_provider()
#> [1] "VISA 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "American Express" "VISA 13 digit"    "VISA 16 digit"    "JCB 16 digit"
ch_credit_card_number()
#> [1] "4185759028312732"
ch_credit_card_number(n = 10)
#>  [1] "55907939779632796"   "869900378411512452"  "6011512815408738054"
#>  [4] "3481832118810066"    "589307285260217"     "4617616190790806"   
#>  [7] "180066249242150468"  "51430534935335826"   "3112229239933866898"
#> [10] "4826101796835"
ch_credit_card_security_code()
#> [1] "648"
ch_credit_card_security_code(10)
#>  [1] "142" "729" "075" "007" "202" "572" "244" "360" "085" "296"

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] "Marylou Balistreri"       "Dr. Ellery Mertz PhD"    
#>  [3] NA                         "Maren Powlowski-Schmitt" 
#>  [5] "Dr. Josiah Lueilwitz DVM" "Donavon Halvorson"       
#>  [7] NA                         "Mr. Add Kutch DDS"       
#>  [9] "Jadyn Brakus"             "Tracy Graham"

numeric data

testVector$make_missing(x = ch_integer(10)) 
#>  [1]  NA  NA  NA 944  NA  NA  NA  NA 791  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 d.d.s."
#>  [3] "Jefferey Lesch"            "Inga Dach"                
#>  [5] "Keyshawn Schaefer"         "Ferdinand Bergstrom"      
#>  [7] "Justen Simonis"            "Ms. Doloris Stroman md"   
#>  [9] "Mrs Ermine Heidenreich"    "Marion Corwin"            
#> [11] "Jalen Grimes"              "Mr. Sullivan Hammes IV"   
#> [13] "Adrien Vandervort-Dickens" "Dr Sharif Kunde"          
#> [15] "Marlena Reichert d.d.s."   "Mr. Brandan Oberbrunner"  
#> [17] "Lloyd Adams Sr"            "Keesha Schowalter"        
#> [19] "Randy Ziemann"             "Gina Sanford"             
#> [21] "Cornell Funk"              "Yadiel Collier"           
#> [23] "Kamryn Johnson"            "Tyesha Schmeler"          
#> [25] "Ernie Hegmann-Graham"      "Zackery Runolfsdottir"    
#> [27] "Cleveland Predovic"        "Melvyn Hickle"            
#> [29] "Larry Nienow I"            "Nicola Langosh Ph.D."     
#> [31] "Ebenezer Fadel V"          "Andrae Hand-Eichmann"     
#> [33] "Shamar Harvey"             "Miss Lynn Altenwerth"     
#> [35] "Willene McLaughlin-Mohr"   "Kyree Kutch"              
#> [37] "Ms Delpha Grant"           "Ms. Icie Crooks"          
#> [39] "Loney Jenkins-Lindgren"    "Shania Donnelly DVM"      
#> [41] "Dr Patric Veum"            "Amirah Rippin DVM"        
#> [43] "Randle Hilpert"            "Soren Dare"               
#> [45] "Roderic Walter"            "Farah Daugherty DDS"      
#> [47] "Ryland Ledner"             "Girtha Harvey DVM"        
#> [49] "Tyrique 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.