R 使用函数中的省略号使用整洁原则读入数据

R 使用函数中的省略号使用整洁原则读入数据,r,tidyverse,ellipsis,rlang,R,Tidyverse,Ellipsis,Rlang,我正在尝试为R包编写一个upload data函数,我希望能够通过省略号将参数传递给我用来读取数据的子函数。我的功能如下: upload_data_excel <- function(directory_path, ...) { # capture ellipsis dots <- rlang::list2(...) # list of file names for upload file_list <- list.files(directory_path,

我正在尝试为R包编写一个upload data函数,我希望能够通过省略号将参数传递给我用来读取数据的子函数。我的功能如下:

upload_data_excel <- function(directory_path, ...) {

  # capture ellipsis
  dots <- rlang::list2(...)

  # list of file names for upload
  file_list <- list.files(directory_path, pattern = '*.xlsx$', full.names = TRUE)

  # concatenate data files
  data <- file_list %>% purrr::map_dfr(~ readxl::read_excel(., !!! dots))

  # clean column names
  data %<>% janitor::clean_names(case = 'snake')

  # output concatenated tibble
  return(data)

}

这种方法正确吗?错误表明我没有在read_excel函数中正确解包点。有什么想法吗?

你可以使用
tryCatch
可能的
安全地捕获
如果(长度(点)==0)数据%purrr::map\u dfr(~readxl::read\u excel(.))其他数据%purr::map\u dfr(~readxl::read\u excel(,!!!点))
您可以使用
tryCatch
可能
安全
捕获如果(长度(点)==0)数据%purrr::map\u dfr(~readxl::read\u excel(.))其他数据%purr::map\u dfr(~readxl::read\u excel(,!!!dots))
Error: `sheet` must have length 1