使用dplyr :: mutate检查自定义因子中的参数会导致RStudio

时间:2016-05-06 09:06:05

标签: r dplyr rstudio

我有一个自定义函数,我想用dplyr mutate。但是,缺少必需参数会导致RStudio崩溃。我不确定这是否是dplyr或RStudio或所需行为的错误。

我想检查一个缺失的参数并停止而不会崩溃RStudion。

我收到的错误消息是

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

我一直在使用missing(),但stopifnot()也会发生这种情况。

require(dplyr)
dat <- data.frame(year = c(201314, 201415), val = c(1,2), 
                  stringsAsFactors = FALSE)

test_fun <- function(x, year_format){
  year_format_list <- c("fyear6", "fyear4", "cyear2")
  if(missing(year_format))
    stop("Year format must be supplied")
  z <- x + 1
  return(z)
}

dat$year2 <- test_fun(dat$year)

dat <- mutate(dat, year3 = test_fun(year))

sessionInfo:

R version 3.3.0 (2016-05-03)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.4.3

loaded via a namespace (and not attached):
[1] magrittr_1.5   R6_2.1.2       assertthat_0.1 parallel_3.3.0 DBI_0.4        tools_3.3.0   
[7] Rcpp_0.12.4 

RStudio版本0.99.896

0 个答案:

没有答案