rename_variable {git2rdata} | R Documentation |
Rename a Variable
Description
The raw data file contains a header with the variable names.
The metadata list the variable names and their type.
Changing a variable name and overwriting the git2rdata
object with result
in an error.
Because it will look like removing an existing variable and adding a new one.
Overwriting the object with strict = FALSE
potentially changes the order of
the variables, leading to a large diff.
Usage
rename_variable(file, change, root = ".", ...)
## S3 method for class 'character'
rename_variable(file, change, root = ".", ...)
## Default S3 method:
rename_variable(file, change, root, ...)
## S3 method for class 'git_repository'
rename_variable(file, change, root, ..., stage = FALSE, force = FALSE)
Arguments
file |
the name of the git2rdata object. Git2rdata objects cannot
have dots in their name. The name may include a relative path. |
change |
A named vector with the old names as values and the new names as names. |
root |
The root of a project. Can be a file path or a |
... |
parameters used in some methods |
stage |
Logical value indicating whether to stage the changes after
writing the data. Defaults to |
force |
Add ignored files. Default is FALSE. |
Details
This function solves this by only updating the raw data header and the metadata.
Value
invisible NULL
.
See Also
Other storage:
list_data()
,
prune_meta()
,
read_vc()
,
relabel()
,
rm_data()
,
verify_vc()
,
write_vc()
Examples
# initialise a git repo using git2r
repo_path <- tempfile("git2rdata-repo-")
dir.create(repo_path)
repo <- git2r::init(repo_path)
git2r::config(repo, user.name = "Alice", user.email = "alice@example.org")
# Create a dataframe and store it as an optimized git2rdata object.
# Note that write_vc() uses optimization by default.
# Stage and commit the git2rdata object.
ds <- data.frame(
a = c("a1", "a2"),
b = c("b2", "b1"),
stringsAsFactors = TRUE
)
junk <- write_vc(ds, "rename", repo, sorting = "b", stage = TRUE)
cm <- commit(repo, "initial commit")
# check that the workspace is clean
status(repo)
# Define change.
change <- c(new_name = "a")
rename_variable(file = "rename", change = change, root = repo)
# check the changes
read_vc("rename", repo)
status(repo)