R/use_.R

Defines functions use_

Documented in use_

#' Title
#'
#' @param path
#'
#' @return
#' @export
#'
#' @examples
use_ <- function(.arg = NULL, .if = NULL, .opt = NULL) {

  path <- stringr::str_remove_all(.arg, "'")

  if (stringr::str_detect(path, ".csv$")) {

    rcode <- stringr::str_glue('dat <<- readr::read_csv("{path}")')

  } else if(stringr::str_detect(path, ".tsv$")) {

    rcode <- stringr::str_glue('dat <<- readr::read_tsv("{path}")')

  } else if (stringr::str_detect(path, ".xls[x]*$")) {

    rcode <- stringr::str_glue('dat <<- readxl::read_excel("{path}")')

  } else if (stringr::str_detect(path, ".dta$")) {

    rcode <- stringr::str_glue('dat <<- haven::read_dta("{path}")')

  }

  rcode <- c(rcode,
             'names(dat) <<- stringr::str_replace_all(names(dat), " +", "_")')

  return(rcode)

}
shohei-doi/transtataR documentation built on March 22, 2021, 1:52 p.m.