knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

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:

See the Creating realistic data vignette for a few realistic examples.

Contributing

See the Contributing to charlatan vignette.

Package API

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()
x$name()
x$job()
x$color_name()

locale support

Here we create 3 jobs, for different locales:

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)

generate a dataset

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

Data types, localized

We can create locale specific versions of:

Examples:

person name

ch_name()
ch_name(10)

phone number

ch_phone_number()
ch_phone_number(10)

job

ch_job()
ch_job(10)

Data types, universal

Some data types are not localized (arguably the files and user_agents, are mostly universal too).

currency

ch_currency(3)

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.



ropensci/charlatan documentation built on Feb. 6, 2025, 1:07 p.m.