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] "Careers adviser"
x$name()
#> [1] "Rasheed Goyette"
x$job()
#> [1] "Engineer, biomedical"
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] "Psychologist, prison and probation services"
#> [2] "Forest/woodland manager"                    
#> [3] "Museum education officer"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Plombier"     "Souscripteur" "Diététicien"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Odgovorna osoba za ocjenjivanje sukladnosti građevinskih proizvoda"
#> [2] "Pirotehničar"                                                      
#> [3] "Djelatnik službe za zaštitu od požara"
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] "MediumVioletRed" "RosyBrown"       "Gainsboro"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Блакитно-фіолетовий"              "Блідо-пісочний"                  
#> [3] "Колір жовтого шкільного автобуса"

generate a dataset

ch_generate()
#> # A tibble: 10 × 3
#>    name                  job                                        phone_number
#>    <chr>                 <chr>                                      <chr>       
#>  1 Malaki Dicki          Musician                                   (532)785-13…
#>  2 Norberto Hilll        Engineer, maintenance (IT)                 +28(1)92150…
#>  3 Claudie Schulist      Hospital doctor                            1-476-604-4…
#>  4 Madyson Parker        Surveyor, minerals                         961-557-746…
#>  5 Chancy Witting        Conservator, furniture                     +22(3)36827…
#>  6 Ari Haag              Programme researcher, broadcasting/film/v… 628-816-9051
#>  7 Caydence Lubowitz DDS Network engineer                           486-397-2481
#>  8 Noble Denesik         Runner, broadcasting/film/video            1-078-906-6…
#>  9 Jovanny Kulas IV      Journalist, newspaper                      08711088186 
#> 10 Cory Fay              Research scientist (physical sciences)     059.482.8222
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                         phone_number      
#>    <chr>                       <chr>             
#>  1 Sports therapist            893-039-5724      
#>  2 Civil Service fast streamer 1-007-431-2132    
#>  3 Technical sales engineer    (268)549-2647x9478
#>  4 Archivist                   03039465132       
#>  5 Corporate treasurer         112.746.6711x4713 
#>  6 Ship broker                 020-350-0394x95307
#>  7 Barrister's clerk           1-841-507-8520    
#>  8 Osteopath                   710.202.7506      
#>  9 Health and safety inspector (255)497-2681     
#> 10 Engineering geologist       +88(5)0995621050  
#> # ℹ 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] "Timmie Streich"
ch_name(10)
#>  [1] "Kayleen Prohaska"      "Burton Kutch"          "Nils Ferry-Johnston"  
#>  [4] "Liller Goodwin"        "Hilbert Runte IV"      "Lorelai Johns DVM"    
#>  [7] "Gerardo Harber"        "Dr. Dania Kirlin MD"   "Tina Gottlieb"        
#> [10] "Mrs. Fatima Heathcote"

phone number

ch_phone_number()
#> [1] "1-313-011-8399x837"
ch_phone_number(10)
#>  [1] "304.423.9723x952"   "422.825.4315x75796" "457-179-8774x36603"
#>  [4] "04847976280"        "087-187-3567x5307"  "1-951-916-5479"    
#>  [7] "(468)028-0200"      "(585)330-2683x8059" "1-860-158-7967x637"
#> [10] "1-397-846-6606"

job

ch_job()
#> [1] "Engineer, communications"
ch_job(10)
#>  [1] "Tax inspector"            "Scientist, biomedical"   
#>  [3] "Phytotherapist"           "Financial risk analyst"  
#>  [5] "Site engineer"            "Medical physicist"       
#>  [7] "Fitness centre manager"   "Journalist, broadcasting"
#>  [9] "Warden/ranger"            "Therapeutic radiographer"

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" "TWD" "MRO"

credit cards

ch_credit_card_provider()
#> [1] "American Express"
ch_credit_card_provider(n = 4)
#> [1] "Diners Club / Carte Blanche" "Diners Club / Carte Blanche"
#> [3] "Maestro"                     "Voyager"
ch_credit_card_number()
#> [1] "3491068649848121"
ch_credit_card_number(n = 10)
#>  [1] "561290481557214"     "4014765677177760"    "3032444055039216"   
#>  [4] "51217024477928872"   "53059480618449023"   "4712238855928"      
#>  [7] "589343281151704"     "4805360370323508"    "4279800748412266"   
#> [10] "3096548617348914912"
ch_credit_card_security_code()
#> [1] "773"
ch_credit_card_security_code(10)
#>  [1] "282"  "7036" "752"  "130"  "235"  "030"  "064"  "1247" "533"  "2841"

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] "Kendell Crona-Jacobson"      "Dr. Burney Wyman DVM"       
#>  [3] "Ms. Rhona Abbott DVM"        "Ciera Cronin"               
#>  [5] NA                            "Dr. Hiroshi Wolff III"      
#>  [7] "Mr. Jeromy Schuster"         "Ms. Diana Runolfsdottir DVM"
#>  [9] "Rakeem Brown"                "Taniya Prohaska"

numeric data

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