#' Set default colnames to variable definition data.frame
#'
#' Replace the colnames defines by user (using \code{user_colnames} argument) by the default slot names of a Variable object. This function help to import variable definition data.frame in other language than English. It is use to import the variable definition data.frame because it reconize the columns with the names.
#'
#' @details The defaults slots for a \code{variable} object are "var_name", "label", "description", "type", "commentary", "levels", "names". To change an column name defined by user, use the syntax \code{list("default_name"="user_name")}, e.g. \code{list("label"="another_name_for_label")}
#' @param df_colnames A character vector with the actual names of the columns in the variable definition data.frame.
#' @param user_colnames A list which replace the default value by an value defined by user. See details
#' @return Return a vector with the default names of the columns
set_vardef_colnames <- function(df_colnames, user_colnames=NULL){
#default colnames are the name of the slots in the variable class
default_colnames <- slotNames("variable")
defaultnames_to_replace <- names(user_colnames)
usernames <- user_colnames
vardef_colnames <- default_colnames
if(!is.null(user_colnames)){
# If therespecific user_colnames
for(a_user_name in usernames){
if
}
} else {
}
return(vardef_colnames)
}
# set_vardef_colnames function
context("Test set_vardef_colnames function")
# Open a test of vardef file
library(openxlsx)
testvardef <- read.xlsx("inst/vardef_samples/Cahier variable test.xlsx")
testcolnames <- colnames(testvardef)
testthat("set_vardef_colnames basic",{
set_vardef_colnames( user_colnames=testcolnames, c("var_name"="variable"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.