mountainMath / cancensus

R wrapper for calling CensusMapper APIs
https://mountainmath.github.io/cancensus/index.html
Other
82 stars 15 forks source link

Unexpected behaviour with parsing region lists if readr package not available #122

Closed dshkol closed 5 years ago

dshkol commented 5 years ago

There appears to be an issue where list_census_region_list can in some situations load and keep region ids as integers instead of converting them into characters. This is not picked up when converting to a region list using as_census_region_list, which will lead to a malformed API call.

This occurs for some users who do not have the readr package installed and for whom the data is loaded using the base read.csv call instead, however there is no need to force a dependency on the readr package. This is straightforward to fix by either ensuring that region_ids are converted to strings in the first step, or by ensuring that they are strings when sent through as_census_region_list.

mountainMath commented 5 years ago

This should fix this, can you test @dshkol? https://github.com/mountainMath/cancensus/pull/123

moh-salah commented 5 years ago

I am not sure if this is a related issue. I get an error when I run this list_census_vectors("CA16"). It used to run just fine a few days ago. Also, it works fine for "CA11". I re-installed the cancensus and readr packages but that didn't help.

Here is the error: Error: '{:name=>"Available Data", :children=>[{"key"=>"CA16", "name"=>"CA 2016 Census", "children"=>[{"name"=>"Population and Dwellings", "children"=>[{"key"=>["v_CA16_401"], "type"=>["Total"], "name"=>"Population, 2016", "add"=>"1", "units"=>1}, {"key"=>["v_CA16_402"], "type"=>["Total"], "name"=>"Population, 2011", "add"=>"1", "units"=>1}, {"key"=>["v_CA16_403"], "type"=>["Total"], "name"=>"Population percentage change, 2011 to 2016", "add"=>"2.v_CA16_402", "units"=>1}, {"key"=>["v_CA16_404"], "type"=>["Total"], "name"=>"Total private dwellings", "add"=>"1", "units"=>1, "children"=>[{"key"=>["v_CA16_405"], "type"=>["Total"], "name"=>"Private dwellings occupied by usual residents", "add"=>"1", "prop"=>1, "units"=>1}]}, {"key"=>["v_CA16_406"], "type"=>["Total"], "name"=>"Population density per square kilometre", "add"=>"2.v_CA16_407", "units"=>4}, {"key"=>["v_CA16_407"], "type"=>["Total"], "name"=>"Land area in square kilometres", "add"=>"1", "units"=>1}]}, {"name"=>"100% data", "child

@mountainMath, Any ideas on how to fix this?

Thanks!

mountainMath commented 5 years ago

That's a bug, I get the same result. Looks like the server is sending json data instead of CSV. Thanks for flagging that. Will take a look tonight.

mountainMath commented 5 years ago

Ah, was a problem with the cache on the server. I used the same cache key for json and csv format. People rarely request the json, so it did not show up earlier. Fixed now. Thanks again for flagging this @moh-salah!