R/get_var_names_dic.R

Defines functions get_var_names_dic

Documented in get_var_names_dic

#' outputs a dictionary (excel utf8 csv) of the names of variables of a given tibble
#' this is used with EXCEL for renaming variables
#'
#' @param .data a tbl() to output its names
#' @param folder_name the folder name as *string* to which the dictionary will be saved in.
#' the default name of the folder is "data"
#' @param name the file name as *string* . please finish the file name with .csv
#' the default name of the file is "var_names_dic.csv"
#'
#' @return A tbl, with two identical variables, vars and new.
#' in addition, the function saves the file in the specified folder
#'
#' @examples
#' school <- tribble(
#'   ~NAME, ~CLASS, ~GRADE,
#'   yossy, first, 70,
#'   dina, second, 90,
#'   reut, third, 100,
#'   dvir, first, 30
#'   )
#'
#' get_value_dic(school,folder_name="mydata",name="school_var_names_dic.csv")
#'
#' @seealso get_value_dic, get_diffrent_var_names
#' @importFrom magrittr %>%
#' @importFrom stringr str_replace_all
#' @export



get_var_names_dic <- function(.data, folder_name="data", name="var_names_dic.csv"){


  warning("this function is no longer supprted, use make_header_template instead")

  vars <- names(.data)
  new <- names(.data)

  var_names_dic <- tibble::tibble(vars,new) %>%
    mutate(new = stringr::str_replace_all(new,"\\n",""))

  readr::write_excel_csv(var_names_dic,path = paste0(folder_name,"/",name))

  return(var_names_dic)



}
sarid-ins/saridr documentation built on Nov. 10, 2020, 9:07 p.m.