Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用管道的自有函数内自有函数中的Tidyeval_R_Tidyverse_Devtools_Rlang_Tidyeval - Fatal编程技术网

R 使用管道的自有函数内自有函数中的Tidyeval

R 使用管道的自有函数内自有函数中的Tidyeval,r,tidyverse,devtools,rlang,tidyeval,R,Tidyverse,Devtools,Rlang,Tidyeval,因此,我正在尝试制作一个包(我没有在下面包含我的roxygen2标题): 我有这个功能: date_from_text <- function(df, x){ x <- rlang::enquo(x) name <- rlang::quo_name(x) df %>% dplyr::mutate(!!name := lubridate::ymd_hms(!!x)) } 更新:所以我现在将date\u从_text添加到date\u列中 date_co

因此,我正在尝试制作一个包(我没有在下面包含我的roxygen2标题):

我有这个功能:

date_from_text <- function(df, x){
  x <- rlang::enquo(x)
  name <- rlang::quo_name(x)

  df %>%
    dplyr::mutate(!!name := lubridate::ymd_hms(!!x))
}
更新:所以我现在将
date\u从_text
添加到
date\u列中

date_columns <- function(df, x){
  x <- rlang::enquo(x)

  out <-  df %>%
    date_from_text(!!x) %>%
      dplyr::mutate(year=lubridate::year(!!x),
           ydag=lubridate::yday(!!x),
           weekday=lubridate::wday(!!x, label=FALSE),
           hour = lubridate::hour(!!x),
           hour_min= hms::as.hms(lubridate::force_tz(!!x)),
           week_num = lubridate::week(!!x),
           month = lubridate::month(!!x),
           date = lubridate::date(!!x))
 out

  }

date\u columns如评论和聊天中所述,问题既不是关于包开发和名称空间,也不是关于管道。问题是如何在可能嵌套的包装函数中使用

答案是,用户传递给函数的表达式需要是,就像下面通过
enquo(x)
date\u from\u text()
中一样!!x

date\u from\u text让我们看看。
df <- structure(list(time = c("2018-01-30 20:08:18", "2018-02-01 21:01:25", 
"2018-01-31 23:25:12", "2018-01-28 23:45:34", "2018-01-31 12:00:55", 
"2018-02-04 09:15:31", "2018-01-27 21:08:02", "2018-02-08 01:50:31", 
"2018-02-01 03:15:43", "2018-02-04 01:04:52"), type = c("A", 
"D", "B", "B", "B", "D", "C", "C", "C", "A")), .Names = c("time", 
"type"), row.names = c(NA, -10L), class = c("tbl_df", "tbl", 
"data.frame"))
date_columns <- function(df, x){
  x <- rlang::enquo(x)

  out <-  df %>%
    date_from_text(!!x) %>%
      dplyr::mutate(year=lubridate::year(!!x),
           ydag=lubridate::yday(!!x),
           weekday=lubridate::wday(!!x, label=FALSE),
           hour = lubridate::hour(!!x),
           hour_min= hms::as.hms(lubridate::force_tz(!!x)),
           week_num = lubridate::week(!!x),
           month = lubridate::month(!!x),
           date = lubridate::date(!!x))
 out

  }