Introduction to the charlatan package

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:

Contributing

See the Contributing to charlatan vignette

Package API

Install

Stable version from CRAN

install.packages("charlatan")

Development version from Github

devtools::install_github("ropensci/charlatan")
library("charlatan")

high level function

... for all fake data operations

x <- fraudster()
x$job()
x$name()
x$job()
x$color_name()

locale support

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 ...

generate a dataset

ch_generate()
ch_generate("job", "phone_number", n = 30)

Data types

person name

ch_name()
ch_name(10)

phone number

ch_phone_number()
ch_phone_number(10)

job

ch_job()
ch_job(10)

credit cards

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)

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)

numeric data

testVector$make_missing(x = ch_integer(10))

logicals

set.seed(123)
testVector$make_missing(x = sample(c(TRUE, FALSE), 10, replace = 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)

Right now only suffixes and prefixes for names in en_US locale are supported. Notice above some variation in prefixes and suffixes.



Try the charlatan package in your browser

Any scripts or data that you put into this service are public.

charlatan documentation built on Sept. 13, 2023, 5:08 p.m.