简体   繁体   English

R-检查是否为真:需要TRUE / FALSE的缺失值

[英]R - check if it is true: missing value where TRUE/FALSE needed

Why do I get this error message: 为什么我收到此错误消息:

missing value where TRUE/FALSE needed

I want to check if it is true then do something. 我想检查一下是否正确,然后做点什么。 This works OK on my RStudio but I get the error above when the code is on the production server: 这在我的RStudio上可以正常工作,但是当代码在生产服务器上时出现上述错误:

na <- all(is.na(Df[, columnName]))
if (isTRUE(na)) {
   # do something
}

It is the same for: 它与以下内容相同:

if (na == TRUE) {

Any idea why?? 知道为什么吗?

EDIT: 编辑:

It seems that it is all(is.na(Df[, columnName])) that is causing this error. 似乎是all(is.na(Df[, columnName]))导致此错误。

My Shiny on my production server is on an older version - 0.12.1 . 生产服务器上的My Shiny使用的是旧版本-0.12.1 While my local machine is on 1.0.3. 当我的本地计算机在1.0.3上时。 How can I verify whether it is the problem of the Shiny versions? 如何验证是否是Shiny版本的问题?

Below are my data samples. 以下是我的数据样本。

This data has no error : 此数据没有错误

structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L), .Label = "LW2", class = "factor"), code = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "LW2", class = "factor"), 
    date = structure(c(1493251200, 1493254800, 1493258400, 1493262000, 
    1493265600, 1493269200, 1493272800, 1493276400, 1493280000, 
    1493283600, 1493287200, 1493290800, 1493294400, 1493298000, 
    1493301600, 1493305200, 1493308800, 1493312400, 1493316000, 
    1493319600, 1493323200, 1493326800, 1493330400, 1493334000
    ), class = c("POSIXct", "POSIXt"), tzone = "GMT"), PM25 = c(4.4, 
    4.3, 5.3, 2.1, 4.3, 16.1, 21.1, 22.7, 27.8, 22.2, 11.3, 13.4, 
    14.2, 13.8, 15.9, 17.6, 18.5, 24.7, 23, 31.6, 18.9, 23, 11.7, 
    11.7)), row.names = c(NA, -24L), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), .Names = c("site", "code", "date", 
"PM25"), vars = list(site, code), drop = TRUE, indices = list(
    0:23), group_sizes = 24L, biggest_group_size = 24L, labels = structure(list(
    site = structure(1L, .Label = "LW2", class = "factor"), code = structure(1L, .Label = "LW2", class = "factor")), row.names = c(NA, 
-1L), class = "data.frame", vars = list(site, code), drop = TRUE, .Names = c("site", 
"code")))

This data gives the error above: 此数据给出上面的错误

structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L), .Label = "HK6", class = "factor"), code = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "HK6", class = "factor"), 
    date = structure(c(1493251200, 1493254800, 1493258400, 1493262000, 
    1493265600, 1493269200, 1493272800, 1493276400, 1493280000, 
    1493283600, 1493287200, 1493290800, 1493294400, 1493298000, 
    1493301600, 1493305200, 1493308800, 1493312400, 1493316000, 
    1493319600, 1493323200, 1493326800, 1493330400, 1493334000
    ), class = c("POSIXct", "POSIXt"), tzone = "GMT"), PM25 = c(NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
    NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN)), row.names = c(NA, 
-24L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), .Names = c("site", 
"code", "date", "PM25"), vars = list(site, code), drop = TRUE, indices = list(
    0:23), group_sizes = 24L, biggest_group_size = 24L, labels = structure(list(
    site = structure(1L, .Label = "HK6", class = "factor"), code = structure(1L, .Label = "HK6", class = "factor")), row.names = c(NA, 
-1L), class = "data.frame", vars = list(site, code), drop = TRUE, .Names = c("site", 
"code")))

I am checking the column name of PM25 . 我正在检查PM25的列名。

The statement within the if condition might be giving NA . if条件内的语句可能会给出NA You can avoid that using: 您可以避免使用:

if (all(is.na(Df[, columnName]))) {
   # do something
}

I am not sure of your exact context, but you can try this. 我不确定您的确切背景,但是您可以尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM