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 (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

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] "Research scientist (maths)"
x$name()
#> [1] "Miss Breanne Fadel MD"
x$job()
#> [1] "Physicist, medical"
x$color_name()
#> [1] "Lavender"

locale support

Adding more locales through time, e.g.,

Locale support for job data

ch_job(locale = "en_US", n = 3)
#> [1] "Designer, interior/spatial" "Electronics engineer"      
#> [3] "Public affairs consultant"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Éleveur"            "Dresseur d'animaux" "Hydraulicien"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Magistar sanitarnog inženjerstva" "Krojač muške odjeće"             
#> [3] "Direktor predstavništva"
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] "DimGray"   "SlateGray" "Lavender"
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 Miss Santos Ebert      Therapist, drama                    1-959-867-1554    
#>  2 Doll Becker            Stage manager                       (108)247-3142     
#>  3 Ernesto Robel          Set designer                        (454)855-9870x341 
#>  4 Sharron Spinka         Administrator                       (917)368-7747     
#>  5 Hailey Balistreri      IT consultant                       052-812-1228x0658 
#>  6 Mrs. Kati Daniel DDS   Research scientist (life sciences)  (097)657-6272x3026
#>  7 Commodore Kunde        Editor, film/video                  01537660710       
#>  8 Armand Ortiz           Designer, blown glass/stained glass (371)499-3471     
#>  9 Lawrance Renner-Sporer Surgeon                             952-879-5008x411  
#> 10 Saverio Padberg        Psychologist, counselling           1-164-372-6974x18…
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                            phone_number      
#>    <chr>                          <chr>             
#>  1 Equality and diversity officer 1-442-676-9088    
#>  2 Civil engineer, consulting     (166)338-7427x592 
#>  3 Hydrogeologist                 08121748690       
#>  4 Personal assistant             +37(6)7827894588  
#>  5 Curator                        186-814-9343x78843
#>  6 Database administrator         (688)746-7413x956 
#>  7 Radio producer                 1-931-132-9519    
#>  8 Technical brewer               273-725-2599x30571
#>  9 Sports therapist               +65(8)7421056783  
#> 10 Restaurant manager             987-576-3745x62701
#> # ℹ 20 more rows

Data types

person name

ch_name()
#> [1] "Johnathan Johnston"
ch_name(10)
#>  [1] "Jaime Grant"             "Miss Loria Oberbrunner" 
#>  [3] "Mr. Khalid Boyle"        "Lizeth Ernser"          
#>  [5] "Miss Ednah Predovic PhD" "Randi Frami"            
#>  [7] "Dr. Rashaan Lowe"        "Clell Kunde-Rolfson"    
#>  [9] "Woodrow Kub DDS"         "Tristen Hirthe"

phone number

ch_phone_number()
#> [1] "536.970.8342x9203"
ch_phone_number(10)
#>  [1] "(815)983-4344"       "513.288.9299"        "003-003-3956"       
#>  [4] "1-949-397-1121"      "992.603.0046"        "(471)682-3717"      
#>  [7] "968.614.1761x0050"   "04205022159"         "1-568-931-7385x8633"
#> [10] "1-958-132-5291x1429"

job

ch_job()
#> [1] "Retail banker"
ch_job(10)
#>  [1] "Aid worker"                    "Artist"                       
#>  [3] "Counsellor"                    "Operational investment banker"
#>  [5] "Animal nutritionist"           "Microbiologist"               
#>  [7] "Psychologist, forensic"        "Futures trader"               
#>  [9] "Research scientist (medical)"  "Gaffer"

credit cards

ch_credit_card_provider()
#> [1] "JCB 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "JCB 16 digit"     "American Express" "VISA 16 digit"    "VISA 16 digit"
ch_credit_card_number()
#> [1] "180051635305835168"
ch_credit_card_number(n = 10)
#>  [1] "3746955325873959"    "6011304691359107843" "869939157393062149" 
#>  [4] "3419579073050553"    "3734984464693410"    "4037742458123050"   
#>  [7] "4042223205479"       "52538537189706411"   "639034898805923"    
#> [10] "3465649070951625"
ch_credit_card_security_code()
#> [1] "519"
ch_credit_card_security_code(10)
#>  [1] "639"  "029"  "400"  "2846" "763"  "210"  "7614" "545"  "3193" "477"

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] "Jaleesa Pouros"     "Rayford Thompson"   "Clotilde Beahan"   
#>  [4] "Pollie Padberg"     "Octavie Wintheiser" "Kieth Franecki"    
#>  [7] "Liam Lubowitz"      "Keila Gislason DVM" NA                  
#> [10] NA

numeric data

testVector$make_missing(x = ch_integer(10))
#>  [1] 648 502 312  NA 811 970  34 817 133 629

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.