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.

rename_variable(file, change, root = ".", ...)

# S3 method for character
rename_variable(file, change, root = ".", ...)

# S3 method for default
rename_variable(file, change, root, ...)

# S3 method for git_repository
rename_variable(file, change, root, ..., stage = FALSE, force = FALSE)



the name of the git2rdata object. Git2rdata objects cannot have dots in their name. The name may include a relative path. file is a path relative to the root. Note that file must point to a location within root.


A named vector with the old names as values and the new names as names.


The root of a project. Can be a file path or a git-repository. Defaults to the current working directory (".").


parameters used in some methods


Logical value indicating whether to stage the changes after writing the data. Defaults to FALSE.


Add ignored files. Default is FALSE.


invisible NULL.


This function solves this by only updating the raw data header and the metadata.

See also

Other storage: list_data(), prune_meta(), read_vc(), relabel(), rm_data(), verify_vc(), write_vc()


# initialise a git repo using git2r
repo_path <- tempfile("git2rdata-repo-")
repo <- git2r::init(repo_path)
git2r::config(repo, = "Alice", = "")

# 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
#> working directory clean

# Define change.
change <- c(new_name = "a")
rename_variable(file = "rename", change = change, root = repo)
#> ec551b8fd0164c484d0a68709017d9d547d83bea 
#>                             "rename.tsv" 
#> 34818c45742ac845b073ebbbc87411abb2dc7ac7 
#>                             "rename.yml" 
# check the changes
read_vc("rename", repo)
#>   new_name  b
#> 1       a2 b1
#> 2       a1 b2
#> Unstaged changes:
#> 	Modified:   rename.tsv
#> 	Modified:   rename.yml