assert = function (expr, error) {
# Original source: @max-gasner
# https://stackoverflow.com/questions/8343509/better-error-message-for-stopifnot
if (! expr) stop(error, call. = FALSE)
}
boolean = function(x, true_values=c("true", "t", "yes", "1"), false_values=c("false", "f", "no", "0"), assertion_message="Please choose either: TRUE or FALSE"){
option = NULL
x = tolower(as.character(x))
(if x %in% true_values){
option = TRUE
}
(if x %in% false_values){
option = FALSE
}
assert(is.logical(options), assertion_message)
return option
}
在中时会发生以下情况rstudio
:
> assert = function (expr, error) {
+ # Original source: @max-gasner
+ # https://stackoverflow.com/questions/8343509/better-error-message-for-stopifnot
+ if (! expr) stop(error, call. = FALSE)
+ }
>
>
> boolean = function(x, true_values=c("true", "t", "yes", "1"), false_values=c("false", "f", "no", "0"), assertion_message="Please choose either: TRUE or FALSE"){
+ option = NULL
+ x = tolower(as.character(x))
+ (if x %in% true_values){
Error: unexpected symbol in:
" x = tolower(as.character(x))
(if x"
> option = TRUE
> }
Error: unexpected '}' in " }"
> (if x %in% false_values){
Error: unexpected symbol in " (if x"
> option = FALSE
> }
Error: unexpected '}' in " }"
> assert(is.logical(options), assertion_message)
Error in stop(error, call. = FALSE) :
object 'assertion_message' not found
> return(option)
Error: no function to return from, jumping to top level
> }
Error: unexpected '}' in "}"
我检查了一下:错误:“}”中意外的'}',它不是来自Unicode字符。
问题在于 (
(if x %in% true_values)
^^
相似地
(if x %in% false_values)
^^
这将是
if(x %in% true_values)
和
if(x %in% false_values)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句