我的职能和评论是:
#' @examples check_duplication(iris,col_names = "Sepal.Length",check_type = F)
# check_duplication(iris,col_names = "Sepal.Width")
check_duplication <- function(data,col_names,check_type=T){
if(check_type){ data <- as.data.frame(data)}
duplicate_nums<- nrow(data)-nrow(as.data.frame(base::unique(data[,col_names])))
return(duplicate_nums)
}当我使用devtools::check()时,它将在testthat测试和控制台上工作,它报告错误
我知道当我用F代替假的时候,这个错误会发生,但是这是什么原因呢?
checking examples ... ERROR
Running examples in ‘datools-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: check_duplication
> ### Title: check data unique
> ### Aliases: check_duplication
>
> ### ** Examples
>
> check_duplication(iris,col_names = "Sepal.Length",check_type = F)
Error in check_duplication(iris, col_names = "Sepal.Length", check_type = F) :
F used instead of FALSE
Execution halted我有两个问题:
中真与F有什么区别
谢谢你的帮助~
发布于 2019-12-28 14:06:45
如消息所示,使用FALSE而不是F。
F是变量,FALSE是常量。使用F是危险的,因为用户可能有类似于F <- 100的代码,然后使用默认的check_type = F,
if (check_type) { data <- as.data.frame(data)}将执行该子句,因为100的计算结果与TRUE相同。
如果用户尝试
FALSE <- 100它将被标记为语法错误。
https://stackoverflow.com/questions/59508972
复制相似问题