
Introduction to the charlatan package
Scott Chamberlain
Roel M. Hogervorst
2023-12-04
Source:vignettes/charlatan.Rmd
charlatan.Rmd
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 incharlatan
-
fraudster()
- single interface to all fake data methods, - returns vectors/lists of data - this function wraps thech_*()
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] "Cabin crew"
x$name()
#> [1] "Dr. Jerrad Braun I"
x$job()
#> [1] "Nature conservation officer"
x$color_name()
#> [1] "OldLace"
locale support
Adding more locales through time, e.g.,
Locale support for job data
ch_job(locale = "en_US", n = 3)
#> [1] "Research scientist (physical sciences)"
#> [2] "Fisheries officer"
#> [3] "Barrister's clerk"
ch_job(locale = "fr_FR", n = 3)
#> [1] "Secrétaire" "Chargé d'études économiques"
#> [3] "Responsable de réseau eau potable"
ch_job(locale = "hr_HR", n = 3)
#> [1] "Pekar" "Dimnjačar" "Stolar"
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] "DarkSeaGreen" "FloralWhite" "Crimson"
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 Ms. Kaiya Price Nurse, mental health 785.017.914…
#> 2 Dr. Jimmy Schroeder III Conservation officer, historic buildin… 725.143.2597
#> 3 Sincere Bergstrom Therapist, sports 1-916-970-6…
#> 4 Dr. Arnulfo Pfeffer Sr. Clinical biochemist 1-365-171-5…
#> 5 Tory Grimes Homeopath 708-660-5063
#> 6 Mrs. Rosann Goyette DDS Comptroller 798.114.6720
#> 7 Mathew Rosenbaum Best boy 1-354-322-0…
#> 8 Mr. Ned Satterfield Education officer, community 1-046-445-1…
#> 9 Mrs. Tamala Pfannerstill Systems analyst 872.098.7255
#> 10 Drury Lebsack Furniture designer +82(6)45367…
ch_generate("job", "phone_number", n = 30)
#> # A tibble: 30 × 2
#> job phone_number
#> <chr> <chr>
#> 1 Copywriter, advertising 1-607-535-6368x2083
#> 2 Artist (313)991-9209x307
#> 3 Astronomer 219-519-5350x631
#> 4 Podiatrist 605-348-7548x2551
#> 5 Ophthalmologist 030.652.3669x590
#> 6 Tour manager 1-698-204-8063x1869
#> 7 Civil Service administrator (977)289-7863x321
#> 8 Secretary/administrator 02700464227
#> 9 Regulatory affairs officer 890-328-7343
#> 10 Merchandiser, retail (862)723-8754x4726
#> # ℹ 20 more rows
Data types
person name
ch_name()
#> [1] "Carmela Ortiz"
ch_name(10)
#> [1] "Pairlee Littel" "Christi Von" "Mrs. Ilah Wolff"
#> [4] "Scarlet Yost" "Dylan Kris-Hilpert" "Benjamin Goodwin PhD"
#> [7] "Wayde Gerlach Jr." "Zackary Lubowitz" "Izola Breitenberg"
#> [10] "Kordell Koss"
phone number
ch_phone_number()
#> [1] "+47(5)8942794052"
ch_phone_number(10)
#> [1] "605.504.8723x2537" "959-610-0196x41378" "764.273.9364"
#> [4] "034-339-3355" "+21(7)8493099694" "+44(9)4592304063"
#> [7] "233-868-1649" "(595)631-6235" "(261)603-0359"
#> [10] "730-510-8884"
job
ch_job()
#> [1] "Astronomer"
ch_job(10)
#> [1] "Investment banker, operational" "Building surveyor"
#> [3] "Tourist information centre manager" "IT sales professional"
#> [5] "Community education officer" "Environmental consultant"
#> [7] "Midwife" "Lecturer, higher education"
#> [9] "Television floor manager" "Editor, film/video"
credit cards
ch_credit_card_provider()
#> [1] "Voyager"
ch_credit_card_provider(n = 4)
#> [1] "JCB 16 digit" "Voyager" "VISA 16 digit" "Discover"
ch_credit_card_number()
#> [1] "3528550731134503600"
ch_credit_card_number(n = 10)
#> [1] "4585899757655707" "3158280292025722921" "3158508720231237934"
#> [4] "3042184030913503" "6011041407397559236" "3793640823277919"
#> [7] "6011577972662048019" "6011677876244004748" "4501657767479919"
#> [10] "4449143559441677"
ch_credit_card_security_code()
#> [1] "000"
ch_credit_card_security_code(10)
#> [1] "536" "829" "197" "290" "927" "864" "991" "716" "255" "812"
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 NA NA NA NA NA NA NA
numeric data
testVector$make_missing(x = ch_integer(10))
#> [1] NA NA NA NA NA NA NA NA NA 269
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.