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] "Retail manager"
x$name()
#> [1] "Arvid Ebert"
x$job()
#> [1] "Photographer"
x$color_name()
#> [1] "DarkOrange"

locale support

Adding more locales through time, e.g.,

Locale support for job data

ch_job(locale = "en_US", n = 3)
#> [1] "Brewing technologist" "Set designer"         "Financial trader"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Professeur de collège et de lycée" "Projectionniste"                  
#> [3] "Substitut du procureur"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Ovlašteni revident iz zaštite od požara"
#> [2] "Vođa palube"                            
#> [3] "Diplomirani sanitarni inženjer"
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] "DarkKhaki" "Chocolate" "SeaShell"
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 Chrissie Schaden-Roob     Hospital pharmacist    448-430-9595x571   
#>  2 Dondre Dickinson          Water engineer         731-600-3657x9307  
#>  3 Ms. Claire Turcotte       Tour manager           245.743.2271x520   
#>  4 Ms. Neha Medhurst PhD     Applications developer (999)820-8450      
#>  5 Felicitas Langosh         Professor Emeritus     1-132-226-8618x2318
#>  6 Wilhelmina Bergnaum       Actuary                734.836.7084       
#>  7 Lynette Kihn              Adult guidance worker  08428563454        
#>  8 Christiana Lebsack        Air broker             (993)656-5492      
#>  9 Mrs. Shannen Nitzsche DVM Haematologist          078-972-7295x8507  
#> 10 Dr. Kaylee Kub PhD        Sports therapist       505.288.8092
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                                phone_number        
#>    <chr>                              <chr>               
#>  1 Copy                               1-980-744-1550x124  
#>  2 Cartographer                       806-864-7282x1878   
#>  3 Secretary/administrator            01607676528         
#>  4 Contractor                         487-100-9388        
#>  5 Public relations account executive 637-295-1309        
#>  6 Accounting technician              1-744-842-9895x99838
#>  7 Lecturer, higher education         742.945.5747x3489   
#>  8 Engineer, chemical                 1-758-995-9457      
#>  9 Mining engineer                    (772)235-8496       
#> 10 Air cabin crew                     028.063.6087x809    
#> # ℹ 20 more rows

Data types

person name

ch_name()
#> [1] "Joseluis Nikolaus"
ch_name(10)
#>  [1] "Cydney Littel"         "Anie Zieme-Auer"       "Philomena Harris"     
#>  [4] "Dr. Trinity Grant Sr." "Mae Waelchi"           "Dejuan Kutch"         
#>  [7] "Ena Watsica PhD"       "Mr. Laverne Kovacek"   "Steve Lind-Hand"      
#> [10] "Cash Kirlin"

phone number

ch_phone_number()
#> [1] "05967903248"
ch_phone_number(10)
#>  [1] "1-751-481-0807x756"  "00880855380"         "+91(2)0084558714"   
#>  [4] "1-107-941-7096x658"  "(594)457-8498"       "536.486.2327x2590"  
#>  [7] "+64(5)2608456015"    "1-566-874-5116"      "+40(4)3630480111"   
#> [10] "1-365-525-8749x3030"

job

ch_job()
#> [1] "Print production planner"
ch_job(10)
#>  [1] "Administrator, sports"              "Designer, exhibition/display"      
#>  [3] "Market researcher"                  "Arts development officer"          
#>  [5] "Quality manager"                    "Plant breeder/geneticist"          
#>  [7] "Public relations account executive" "Administrator, education"          
#>  [9] "Visual merchandiser"                "Newspaper journalist"

credit cards

ch_credit_card_provider()
#> [1] "VISA 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "Maestro"                     "JCB 15 digit"               
#> [3] "American Express"            "Diners Club / Carte Blanche"
ch_credit_card_number()
#> [1] "4598594397321399"
ch_credit_card_number(n = 10)
#>  [1] "3158911260946170261" "676356459758191"     "4876024360014634"   
#>  [4] "6011989288890775212" "6011778366017951562" "3002512916646351"   
#>  [7] "4712023510170120"    "3436211715797073"    "3528667199518011436"
#> [10] "3037508840856673"
ch_credit_card_security_code()
#> [1] "236"
ch_credit_card_security_code(10)
#>  [1] "425"  "104"  "463"  "353"  "848"  "898"  "818"  "7658" "518"  "783"

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] NA                "Katerina Lynch"  NA                "Gaylord Mills"  
#>  [5] "Bernetta Wehner" NA                NA                "Marion Padberg" 
#>  [9] NA                NA

numeric data

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