| data_code | R Documentation |
data_code compares an original dataset with an edited version and
generates tidyverse-style R code (using dplyr verbs) that transforms
the original data into the edited version. The generated code uses
rename(), select(), mutate(), slice(), and
tibble::add_row() to replicate column renames, column
additions/removals, cell value changes, and row additions/removals. When
meaningful row names are present (i.e. non-default row names such as those
in mtcars), the generated code preserves them using
tibble::rownames_to_column() and tibble::column_to_rownames().
data_code(x, x_edit, name = "data")
x |
original data prior to editing, a |
x_edit |
edited data after modifications, a |
name |
character string for the name of the data object in the generated
code, set to |
a character string containing tidyverse code that can be printed to the console or written to an R script.
Dillon Hammill, dillon.hammill21@gmail.com
# original data
x <- data.frame(
A = c(1, 2, 3),
B = c("x", "y", "z"),
stringsAsFactors = FALSE
)
# edited data (changed a value and renamed a column)
x_edit <- data.frame(
A = c(1, 5, 3),
Beta = c("x", "y", "z"),
stringsAsFactors = FALSE
)
# generate code
cat(data_code(x, x_edit, name = "x"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.