Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning messages: Unknown column 'XYZ' #2396

Closed
codingbutstillalive opened this issue Jan 31, 2017 · 11 comments
Closed

Warning messages: Unknown column 'XYZ' #2396

codingbutstillalive opened this issue Jan 31, 2017 · 11 comments
Labels
reprex needs a minimal reproducible example

Comments

@codingbutstillalive
Copy link

codingbutstillalive commented Jan 31, 2017

I once used add_column to add a new column to my data frame, something along the line of:

dat <- dat %>% add_column(QUARTAL=rep(NA, nrow(dat)))
dat$QUARTAL[dat$MONTH %in% 1:3] <- "Q1"
dat$QUARTAL[dat$MONTH %in% 4:6] <- "Q2"
dat$QUARTAL[dat$MONTH %in% 7:9] <- "Q3"
dat$QUARTAL[dat$MONTH %in% 10:12] <- "Q4"

dat$QUARTAL <- as.factor(dat$QUARTAL)

Since then, every now and then I get warning messages "Unknown column 'QUARTAL'". Those appear arbitrarily upon invoking commands, not only when issuing the add_column command. I have no clue why.

I already cleared up the whole environment and tried to reset the cache of latest warnings like this:

assign("last.warning", NULL, envir = baseenv())

Nothing helps.

@hadley
Copy link
Member

hadley commented Jan 31, 2017

Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you!

If you've never heard of a reprex before, start by reading "What is a reprex", and follow the advice further down the page.

@hadley hadley added the reprex needs a minimal reproducible example label Jan 31, 2017
@adisarid
Copy link

adisarid commented Feb 2, 2017

Hi Hadley,
I encountered the same thing just now. It's extremely weird and really hard to reproduce.
This issue "sticks like a gum", even when the environment is cleaned and Rstudio restarted.

I tried reproducing with iris, it's hard to know if I was able to reproduce the bug with it, because I'm still getting warning messages relating to the original dataset I used and not to the new one.
You can try something along the lines of:

data(iris)
iris.tibble <- as_data_frame(iris)
iris.tibble$Sepal.Length.str[iris.tibble$Sepal.Length >= 5] <- "Above 5"
iris.tibble$Sepal.Length.str[iris.tibble$Sepal.Length < 5] <- "Under 5"

Maybe this will do the trick to reproduce the bug. No guarantees though...

I think it's related to the following thread in stackoverflow (which is also unresolved):
http://stackoverflow.com/questions/39041115/fixing-a-multiple-warning-unknown-column
There are some additional examples at that thread.

@codingbutstillalive
Copy link
Author

@adisarid Thanks for you assist, I hadn't had time to figure out a reprex, unfortunately. Your guys are great, thanks so much, also Hadley!

@hadley
Copy link
Member

hadley commented Feb 2, 2017

I don't see the warning, unfortunately.

@adisarid
Copy link

adisarid commented Feb 2, 2017

@hadley
Copy link
Member

hadley commented Feb 2, 2017

@adisarid none of those are a standalone reprex, but I did try and couldn't see the problem.

@zeehio
Copy link
Contributor

zeehio commented Feb 15, 2017

This issue has been dealt at tidyverse/tibble#199.

I suffered this warning but I don't get it anymore. Probably it has been addressed by the development tibble version. In any case the suggested approach is to initialize the column:

data(iris)
iris.tibble <- as_data_frame(iris)
iris.tibble$Sepal.Length.str <- NA # Add this line
iris.tibble$Sepal.Length.str[iris.tibble$Sepal.Length >= 5] <- "Above 5"
iris.tibble$Sepal.Length.str[iris.tibble$Sepal.Length < 5] <- "Under 5"

@hadley hadley closed this as completed Feb 15, 2017
@zeehio
Copy link
Contributor

zeehio commented Mar 1, 2017

@adisarid @codingbutstillalive If you still get these warnings try to add

# !diagnostics off

as the first line in the source code file. Save the file. And try to see if it appears again. There seems to be a bug in Rstudio code diagnostics. I just reported it.

https://support.rstudio.com/hc/en-us/community/posts/115001180488-Diagnostics-and-tibble-warning

Now we can guess that @hadley codes without all the RStudio diagnostics enabled and not being able to reproduce the bug. But if anyone can code without diagnostics is him. 😝

@adisarid
Copy link

adisarid commented Mar 1, 2017

Thanks @zeehio !
I was able to avoid these by using something similar to your previous suggestion.
Finally this makes sense to me... I knew something was weird because I was getting the errors even before running the related code in the script. So I knew it wasn't an error in the code itself which was generating these errors. I didn't know that RStudio has code diagnostics like these.
Thnx.

@zeehio
Copy link
Contributor

zeehio commented Mar 9, 2017

@adisarid, as you may have seen here (stackoverflow) this issue has been addressed today at rstudio/rstudio@bcad791 so it won't affect you in RStudio v1.1.103 or newer (as far as I know that version is not yet published at the RStudio Preview page).

@Ninoninoninonino
Copy link

I had the problem with the unknown column as well.
Converting Tibble back to Dataframe and then using Mutate worked for me.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

5 participants