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

Issue parsing some CSVs via read.csv() #180

Open
sharlagelfand opened this issue Sep 15, 2021 · 0 comments
Open

Issue parsing some CSVs via read.csv() #180

sharlagelfand opened this issue Sep 15, 2021 · 0 comments
Assignees

Comments

@sharlagelfand
Copy link
Contributor

As reported in sharlagelfand/opendatatoronto#11 - there seems to be an issue with reading some CSVs (maybe they're malformed? I haven't looked at the underlying data set quite yet) in read.csv() that something like readr::read_csv() manages just fine.

I'm not sure we want to switch read_session() over to use readr::read_csv() and add that dependency, but maybe could use it as a fallback.

Reprex:

library(ckanr)
library(readr)

id <- "3f93fcb0-c842-4b56-8988-4a84c880b86d"

resource <- resource_show(id, url = "https://ckan0.cf.opendata.inter.prod-toronto.ca/", as = "list")

fetched_resource <- ckan_fetch(resource[["url"]])
#> Warning in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
#> EOF within quoted string

# Versus via readr::read_csv() - bunch of manual steps since this one is in a ZIP

# Make a directory to save into
dir <- tempdir()
resource_dir <- fs::dir_create(paste0(dir, "/", id))

# Save the ZIP file
save_path <- ckan_fetch(resource[["url"]], store = "disk", path = paste0(dir, "/", id, "/", "res.zip"))

# Unzip it
csv_files <- unzip(save_path[["path"]], exdir = resource_dir)

# Read it in 
readr_resource <- read_csv(csv_files, show_col_types = FALSE)

# Compare dims of resources
dim(fetched_resource[[1]])
#> [1] 135718     30
dim(readr_resource)
#> [1] 246434     30

I will look into this more, but reporting here to keep track of.

@sharlagelfand sharlagelfand self-assigned this Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant