Fixing a multiple warning "unknown column" Fixing a multiple warning "unknown column" r r

Fixing a multiple warning "unknown column"


This is an issue with the Diagnostics tool in RStudio (the tool that shows warnings and possible mistakes in your code). It was partially fixed at this commit in RStudio v1.1.103 or later by @kevin-ushey. That fix was partial, because the warnings still appeared (albeit with less frequency). This issue was reported with a reproducible example at https://github.com/rstudio/rstudio/issues/7372 and it was fixed on RStudio v1.4 pull request.

Update to the latest RStudio release to fix this issue. Alternatively, there are several workarounds available, choose the solution you prefer:

  • Disable the code diagnostics for all files in Preferences/Code/Diagnostics

  • Disable all diagnostics for a specific file:

    Add at the beginning of the opened file(s):

     # !diagnostics off

    Then save the files and the warnings should stop appearing.

  • Disable the diagnostics for the variables that cause the warning

    Add at the beginning of the opened file(s):

     # !diagnostics suppress=<comma-separated list of variables>

    Then save the files and the warnings should stop appearing.

The warnings appear because the diagnostics tool in RStudio parses the source code to detect errors and when it performs the diagnostic checks it accesses columns in your tibble that are not initialized, giving the Warning we see. The warnings do not appear because you run unrelated things, they appear when the RStudio diagnostics are executed (when a file is saved, then modified, when you run something...).


I have been encountering the same problem, and although I don't know why it occurs, I have been able to pin down when it occurs, and thus prevent it from happening.

The issue seems to be with adding in a new column, derived from indexing, in a base R data frame vs. in a tibble data frame. Take this example, where you add a new column (age) to a base R data frame:

base_df <- data.frame(id = c(1:3), name = c("mary", "jill","steve"))base_df$age[base_df$name == "mary"] <- 47

That works without returning a warning. But when the same is done with a tibble, it throws a warning (and consequently, I think causing the weird, seemingly unprovoked, multiple warning issue):

library(tibble)tibble_df <- tibble(id = c(1:3), name = c("mary", "jill","steve"))tibble_df$age[tibble_df$name == "mary"] <- 47Warning message:Unknown column 'age' 

There are surely better ways of avoiding this, but I have found that first creating a vector of NAs does the job:

tibble_df$age <- NAtibble_df$age[tibble_df$name == "mary"] <- 47


I have faced this issue when using the "dplyr" package.
For those facing this problem after using the "group_by" function in the "dplyr" library:

I have found that ungrouping the variables solves the unknown column warning problem. Sometimes I have had to iterate through the ungrouping several times until the problem is resolved.