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] "Call centre manager"
x$name()
#> [1] "Daijah Murphy"
x$job()
#> [1] "Hotel manager"
x$color_name()
#> [1] "Wheat"

locale support

Adding more locales through time, e.g.,

Locale support for job data

ch_job(locale = "en_US", n = 3)
#> [1] "Aid worker"                              
#> [2] "Geographical information systems officer"
#> [3] "Engineer, production"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Directeur de magasin à grande surface"
#> [2] "Ingénieur du son"                     
#> [3] "Garde à cheval"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Nadzornik tehničke ispravnosti vozila"              
#> [2] "Ovlašteni inženjer tehnologije prometa i transporta"
#> [3] "Viši preparator"
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] "GoldenRod"  "Silver"     "Aquamarine"
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 Diann Haley PhD          IT trainer                      1-125-527-3427x582
#>  2 Richmond Fritsch         Engineer, manufacturing systems 443-024-4024      
#>  3 Mrs. Shanice Weissnat    Fish farm manager               03202772950       
#>  4 Dr. Keon Rohan DVM       Adult nurse                     02505766385       
#>  5 Mr. Edie Lowe            Product manager                 814-714-2762x4955 
#>  6 Betsey Macejkovic        Recruitment consultant          (712)562-0399     
#>  7 Mr. Isai Yost            Building services engineer      683.167.3770x71467
#>  8 Sherilyn Gottlieb        Insurance underwriter           04453332116       
#>  9 Lavonia Dooley           Forensic psychologist           (170)445-1576x025 
#> 10 Mrs. Shawanda Vandervort Scientist, research (maths)     (156)281-7021
ch_generate('job', 'phone_number', n = 30)
#> # A tibble: 30 × 2
#>    job                             phone_number      
#>    <chr>                           <chr>             
#>  1 Minerals surveyor               07639231879       
#>  2 Therapist, occupational         099.843.9319x961  
#>  3 Information systems manager     (674)388-7633x9334
#>  4 Psychiatric nurse               (056)911-7296     
#>  5 Corporate treasurer             252-629-5292      
#>  6 Medical secretary               06146751571       
#>  7 Early years teacher             694.737.2417      
#>  8 Environmental education officer 029.823.5139      
#>  9 Advertising account executive   678-590-7208      
#> 10 Forest/woodland manager         797.620.6860      
#> # … with 20 more rows

Data types

person name

ch_name()
#> [1] "Londyn Glover-Tromp"
ch_name(10)
#>  [1] "Jerusha Walter"               "Dr. Toma Wehner MD"          
#>  [3] "Ignacio Rowe IV"              "Gabriel Hudson DVM"          
#>  [5] "Thor Anderson"                "Mr. Tremayne Greenfelder Sr."
#>  [7] "Lars Legros-Waters"           "Stefan Emmerich"             
#>  [9] "Wirt Kshlerin"                "Mrs. Love Hackett"

phone number

ch_phone_number()
#> [1] "+42(3)9632036885"
ch_phone_number(10)
#>  [1] "02849802725"          "017-674-0298x62446"   "+68(8)9204175339"    
#>  [4] "1-746-761-3816x96017" "379.347.1960"         "09552098719"         
#>  [7] "(556)851-1834x2103"   "766-217-0480x263"     "574.411.8410x2431"   
#> [10] "1-763-528-2164"

job

ch_job()
#> [1] "Retail buyer"
ch_job(10)
#>  [1] "Lobbyist"                   "Designer, fashion/clothing"
#>  [3] "Animal nutritionist"        "Broadcast journalist"      
#>  [5] "Dramatherapist"             "Barrister"                 
#>  [7] "Insurance account manager"  "Ranger/warden"             
#>  [9] "Stage manager"              "Biochemist, clinical"

credit cards

ch_credit_card_provider()
#> [1] "JCB 15 digit"
ch_credit_card_provider(n = 4)
#> [1] "Maestro"    "Mastercard" "Maestro"    "Mastercard"
ch_credit_card_number()
#> [1] "4636791504047"
ch_credit_card_number(n = 10)
#>  [1] "3772090505486096"    "6011181141831654663" "210034155200939397" 
#>  [4] "503827074347496"     "3337993110893909560" "3158942289212978654"
#>  [7] "4972894425149"       "51809837689294328"   "589310977881787"    
#> [10] "3452078779311094"
ch_credit_card_security_code()
#> [1] "061"
ch_credit_card_security_code(10)
#>  [1] "056"  "338"  "813"  "4869" "448"  "861"  "614"  "388"  "909"  "360"

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                     "Mildred Murray MD"   
#>  [4] "Percival Kuhn-Howell" NA                     NA                    
#>  [7] "Iza Kuphal"           NA                     "Rudy Walsh"          
#> [10] "Dr. Asher Cole Jr."

numeric data

testVector$make_missing(x = ch_integer(10)) 
#>  [1] 248  NA  NA 236 342  NA  NA  NA 249  38

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.