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] "Brewing technologist"
x$name()
#> [1] "Lise Kling"
x$job()
#> [1] "Quality manager"
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] "Product manager"                            
#> [2] "Aeronautical engineer"                      
#> [3] "Psychologist, prison and probation services"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Ingénieur en construction automobile"                        
#> [2] "Ingénieur études et développement en logiciels de simulation"
#> [3] "Guide conférencier des villes et pays d'art et d'histoire"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Odgajatelj u učeničkom domu" "Knjižničar"                 
#> [3] "Autoelektričar"
ch_job(locale = "uk_UA", n = 3)
#> [1] "Модельєр"    "Бібліотекар" "Фрілансер"
ch_job(locale = "zh_TW", n = 3)
#> [1] "塑膠模具技術人員"    "演算法開發工程師"    "CNC電腦程式編排人員"

For colors:

ch_color_name(locale = "en_US", n = 3)
#> [1] "GhostWhite"    "PaleGoldenRod" "Khaki"
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 Alina O'Hara-Stiedemann Exhibitions officer, museum/gallery      601.949.340…
#>  2 Dr. Shawanda Ryan       Print production planner                 818.140.345…
#>  3 Howell Runte            Adult guidance worker                    684.413.533…
#>  4 Mr. Deane Bergnaum DVM  Sports development officer               895.101.5100
#>  5 Arlie Will Jr.          Lighting technician, broadcasting/film/… 01247297529 
#>  6 Lovisa Schamberger      Magazine journalist                      (765)763-17…
#>  7 Roland Veum-Kuhlman     Chief Strategy Officer                   1-130-841-6…
#>  8 Darryle Barton          Conservation officer, historic buildings (273)511-26…
#>  9 Mr. Lenwood Wuckert     Event organiser                          03122954011 
#> 10 Jabez Ortiz             Administrator, Civil Service             542-887-546…
ch_generate('job', 'phone_number', n = 30)
#> # A tibble: 30 × 2
#>    job                                       phone_number      
#>    <chr>                                     <chr>             
#>  1 Set designer                              (295)588-4512x9702
#>  2 Operations geologist                      181-306-7244x8157 
#>  3 Barista                                   +38(3)3977141005  
#>  4 Broadcast engineer                        1-653-931-7044    
#>  5 Surveyor, commercial/residential          789.224.3863x979  
#>  6 Banker                                    119.678.7951      
#>  7 Legal secretary                           132.028.4127x58455
#>  8 Sound technician, broadcasting/film/video 192.065.3644x17688
#>  9 Secretary, company                        04127671791       
#> 10 Garment/textile technologist              (518)808-6327x6449
#> # … with 20 more rows

Data types

person name

ch_name()
#> [1] "Rahsaan Schumm-Thompson"
ch_name(10)
#>  [1] "Kathy Farrell PhD"            "Randle Schneider"            
#>  [3] "Bettyjane Torp"               "Pranav Hayes"                
#>  [5] "Miss Corinna Marvin"          "Dr. Brianne Gorczany DDS"    
#>  [7] "Dr. Emmalee Stroman DDS"      "Mr. Denny Franecki Jr."      
#>  [9] "Miss Kimberley Aufderhar PhD" "Capitola Ryan-Hermann"

phone number

ch_phone_number()
#> [1] "1-139-379-3458x153"
ch_phone_number(10)
#>  [1] "1-347-320-2042x71344" "246.736.7414x8579"    "(211)277-2206"       
#>  [4] "1-438-013-3391x9453"  "(590)621-1232"        "957-587-3255x4942"   
#>  [7] "715.284.3575x08799"   "662-337-8668"         "881.147.1661x24413"  
#> [10] "09552223136"

job

ch_job()
#> [1] "IT technical support officer"
ch_job(10)
#>  [1] "Cytogeneticist"                     "Field seismologist"                
#>  [3] "Surveyor, minerals"                 "Seismic interpreter"               
#>  [5] "Training and development officer"   "Medical sales representative"      
#>  [7] "Surveyor, planning and development" "Podiatrist"                        
#>  [9] "Buyer, retail"                      "Secretary, company"

credit cards

ch_credit_card_provider()
#> [1] "JCB 16 digit"
ch_credit_card_provider(n = 4)
#> [1] "VISA 16 digit" "Maestro"       "Mastercard"    "VISA 16 digit"
ch_credit_card_number()
#> [1] "3021576516792197"
ch_credit_card_number(n = 10)
#>  [1] "3096523727318357361" "4817785134372217"    "53172494484043622"  
#>  [4] "53085035798204750"   "4134852043178071"    "3088573971436419567"
#>  [7] "4170426501897616"    "4245210581993060"    "3401725399851055"   
#> [10] "4655414847385"
ch_credit_card_security_code()
#> [1] "966"
ch_credit_card_security_code(10)
#>  [1] "928" "219" "392" "071" "932" "483" "681" "163" "070" "022"

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                  NA                  NA                 
#>  [4] "Mrs. Mae Cole PhD" NA                  NA                 
#>  [7] NA                  NA                  "Malachi Olson"    
#> [10] NA

numeric data

testVector$make_missing(x = ch_integer(10)) 
#>  [1]  NA  NA  NA  NA  NA  NA  NA  NA  NA 294

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.