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] "Actor"
x$name()
#> [1] "Dr. Milo Gleichner IV"
x$job()
#> [1] "Media planner"
x$color_name()
#> [1] "DarkSlateGray"

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] "Risk manager"                         
#> [2] "Emergency planning/management officer"
#> [3] "Commercial art gallery manager"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Responsable du service après-vente" "Directeur de restaurant"           
#> [3] "Gérant de restauration collective"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Diplomirani knjižničar"                  
#> [2] "Viši muzejski tehničar"                  
#> [3] "Viši inspektor cestovnog prometa i cesta"
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] "SlateBlue"   "Cornsilk"    "ForestGreen"
ch_color_name(locale = "uk_UA", n = 3)
#> [1] "Жовто-зелений"         "Алізариновий червоний" "Джинсовий"

generate a dataset

ch_generate()
#> # A tibble: 10 × 3
#>    name                        job                                  phone_number
#>    <chr>                       <chr>                                <chr>       
#>  1 Lempi Morar                 Conservation officer, nature         901.398.258…
#>  2 Baldwin Schneider-Cummerata Accountant, chartered management     (802)526-85…
#>  3 Ruby Pollich                Chief Financial Officer              +85(5)25531…
#>  4 Silver Stamm                Network engineer                     643-027-967…
#>  5 Dr. Marlo Kuhlman           Scientist, product/process developm… 324-469-6283
#>  6 Mrs. Teresa Ernser MD       Public affairs consultant            313.740.023…
#>  7 Daniele Bailey              Marine scientist                     1-573-696-3…
#>  8 Candace McClure             Textile designer                     1-670-218-3…
#>  9 Tyshawn Trantow-Schumm      Child psychotherapist                810.463.5630
#> 10 Esequiel Padberg            Ceramics designer                    098.242.555…
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#>    job                                    phone_number       
#>    <chr>                                  <chr>              
#>  1 Records manager                        125-947-8871x5833  
#>  2 Tax adviser                            +35(6)1365779713   
#>  3 Librarian, academic                    874-768-7853x87816 
#>  4 Industrial/product designer            114.197.8108       
#>  5 Human resources officer                (193)310-2551x567  
#>  6 Dancer                                 048-796-0464       
#>  7 Editor, magazine features              (087)019-1625x1863 
#>  8 Engineering geologist                  (082)036-1361x47910
#>  9 Geologist, wellsite                    1-253-000-9561x151 
#> 10 Teacher, English as a foreign language 956.006.6518x3735  
#> # ℹ 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] "Arminta Harvey"
ch_name(10)
#>  [1] "Omer Bernhard PhD"      "Lemmie Auer DVM"        "Bob Schiller"          
#>  [4] "Mr. Fremont Hickle PhD" "Ms. Rosita Lebsack"     "Mr. Gustaf Labadie II" 
#>  [7] "Phylis Rolfson PhD"     "Linwood Carroll"        "Essex Dicki"           
#> [10] "Jemal Fahey"

phone number

ch_phone_number()
#> [1] "(838)053-4628x6919"
ch_phone_number(10)
#>  [1] "(546)508-4945"        "571.001.9145"         "407-521-5500"        
#>  [4] "123-605-8089x7258"    "940-112-2712x3874"    "623.502.4374x57022"  
#>  [7] "+99(5)1988549674"     "1-626-210-2640x89767" "1-193-382-2544x669"  
#> [10] "467.369.2586"

job

ch_job()
#> [1] "Jewellery designer"
ch_job(10)
#>  [1] "Energy engineer"                                  
#>  [2] "Actuary"                                          
#>  [3] "Occupational therapist"                           
#>  [4] "Historic buildings inspector/conservation officer"
#>  [5] "Administrator, arts"                              
#>  [6] "Social research officer, government"              
#>  [7] "Astronomer"                                       
#>  [8] "Land/geomatics surveyor"                          
#>  [9] "Manufacturing systems engineer"                   
#> [10] "Nurse, adult"

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] "VND" "BOB" "STD"

credit cards

ch_credit_card_provider()
#> [1] "Diners Club / Carte Blanche"
ch_credit_card_provider(n = 4)
#> [1] "Discover"      "VISA 16 digit" "JCB 16 digit"  "Maestro"
ch_credit_card_number()
#> [1] "3337582498471586794"
ch_credit_card_number(n = 10)
#>  [1] "4694143045887717"    "4013890363602"       "3725806836864638"   
#>  [4] "52334334178405882"   "3528798045780155850" "3039519999360456"   
#>  [7] "3158750375363623347" "3015534826157151"    "3420989419673231"   
#> [10] "589384554499065"
ch_credit_card_security_code()
#> [1] "279"
ch_credit_card_security_code(10)
#>  [1] "271"  "005"  "0023" "340"  "646"  "386"  "423"  "723"  "8682" "352"

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] "Jaelyn Funk"         NA                    NA                   
#>  [4] NA                    "Mrs. Danette Carter" NA                   
#>  [7] NA                    NA                    "Roddy West-Prosacco"
#> [10] NA

numeric data

testVector$make_missing(x = ch_integer(10))
#>  [1] 576  NA  NA 676 883 334 973 322 879 475

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.