knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE )
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:
See the Contributing to charlatan vignette
R6
objects that a user can
initialize and then call methods on. These contain all the logic that
the below interfaces use.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 aboveStable version from CRAN
install.packages("charlatan")
Development version from Github
devtools::install_github("ropensci/charlatan")
library("charlatan")
... for all fake data operations
x <- fraudster() x$job() x$name() x$job() x$color_name()
Adding more locales through time, e.g.,
Locale support for job data
ch_job(locale = "en_US", n = 3) ch_job(locale = "fr_FR", n = 3) ch_job(locale = "hr_HR", n = 3) ch_job(locale = "uk_UA", n = 3) ch_job(locale = "zh_TW", n = 3)
For colors:
ch_color_name(locale = "en_US", n = 3) ch_color_name(locale = "uk_UA", n = 3)
More coming soon ...
ch_generate()
ch_generate("job", "phone_number", n = 30)
ch_name()
ch_name(10)
ch_phone_number()
ch_phone_number(10)
ch_job()
ch_job(10)
ch_credit_card_provider() ch_credit_card_provider(n = 4)
ch_credit_card_number() ch_credit_card_number(n = 10)
ch_credit_card_security_code() ch_credit_card_security_code(10)
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()
testVector$make_missing(x = ch_generate()$name)
testVector$make_missing(x = ch_integer(10))
set.seed(123) testVector$make_missing(x = sample(c(TRUE, FALSE), 10, replace = TRUE))
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)
Right now only suffixes and prefixes for names in en_US
locale
are supported. Notice above some variation in prefixes and suffixes.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.