can't find `agr` columns
mountainMath opened this issue · comments
Getting a really weird error when running
get_census("CA16",regions=list(CSD="5915022"), vectors = c("med_hh_inc"="v_CA16_2397"), geo_format = 'sf')
Error message.
Show in New WindowClear OutputExpand/Collapse Output
Error in rename.sf(., !!!vectors) : internal error: can't find `agr` columns
using sf_0.9-5
Getting the same error from this (in the second line):
d <- get_census("CA16",regions=list(CSD="5915022"), vectors = "v_CA16_2397", geo_format = 'sf', labels="short")
d %>% rename(median_hh_inc=v_CA16_2397)
However, if I replace the second line with
d %>% select(v_CA16_2397) %>% rename(median_hh_inc=v_CA16_2397)
it works.
Was this code that worked before or brand new code? If it worked before, then I suspect it's a tidyselect issue. I've been pretty unhappy to the NSE variable selection syntax since the recent dplyr updates - where it now relies on the tidyselect API on the backend.
Yes, this worked before. Just confirmed by re-running my last blog post. Breaks now. Also, this seems to be an 'sf' issue. Code runs through just fine if no geographies are requested:
get_census("CA16",regions=list(CSD="5915022"), vectors = c("med_hh_inc"="v_CA16_2397"))
Do you still have older sf
or the newest one? Does it work for you?
Ok, I think I found the problem. Somehow this issue is caused by the line in our code that renames vectors to 'short' form. if we replace that line with
else {result <- rename(result,!!!setNames(names(.),gsub(":.*","",names(.))))}
Everything works out. Somehow assigning
names(result)=gsub(":.*","",names(result))
breaks something for sf
objects.
Merged a fix directly into master.
This introduces new errors - as seen by the CI errors.
For starters
rename(result,!!!setNames(names(.),gsub(":.*","",names(.))))}
should be
dplyr::rename(result,!!!setNames(names(.),gsub(":.*","",names(.))))}
but then that still causes the other error.
I was using sf 0.9-3
- updating now.
In the future let's not commit changes like that to master. The error likely didnt come up for you locally because of caching. It didn't for me either with this commit until I forced refresh of data.
Ouch, yes, that one is on me.
fixed now