Closed rgwood closed 6 years ago
With a bit of testing, I can trace this bug directly to a situation where a user 1) doesn't have the readr
package installed and is making an API call for the first time, or makes the call with a forced refresh of the cache. The error comes from this section of the code, which occurs in each of get_census
, list_census_regions
, and list_census_vectors
.
result <- if (!requireNamespace("readr", quietly = TRUE)) {
dplyr::as_data_frame(utils::read.csv(content, stringsAsFactors = FALSE))
} else {
readr::read_csv(content)
}
If readr
is not installed it tries to use the base function read.csv
to open the content; however, read.csv
is for opening a file connection. In this case, there is no file connection to be made as content
is just a string of text. read_csv
from readr
automatically establishes this text connection step.
There's two ways of fixing this.
1) Establish a text connection to the content
string like this:
result <- if (!requireNamespace("readr", quietly = TRUE)) {
dplyr::as_data_frame(utils::read.csv(textConnection(content), stringsAsFactors = FALSE))
} else {
readr::read_csv(content)
}
or
2) Make readr
a hard dependency and use just that.
Either way works. I don't mind making readr
a hard dependency because we already have dplyr
as one, and most people who use that likely already have readr
installed as a package as well. If we want to maintain the current setup, the fix is easy to implement it and I can add that in, but open to suggestions @mountainMath @atheriel
Thanks, looks like you are on top of things with your pull request. Thanks for flagging this @GRIDSVancouver and thanks for the patch @dshkol.
Fixed in #111
I followed the cancensus installation instructions but was having some trouble running the example commands:
These are my sessionInfo() results:
There is a resolution suggested by @dshkol – install readr (
install.packages('readr')
).