IQSS / dataverse-client-r

R Client for Dataverse Repositories
https://iqss.github.io/dataverse-client-r
61 stars 25 forks source link

Error returned by dataset_versions #27

Closed billy34 closed 3 years ago

billy34 commented 4 years ago

When trying to get versions from my dataset using dataset_versions function I get an errror

Error: $ operator is invalid for atomic vectors

Looking at the code we can notice that there is a missing json decoding of the response

I'll file a PR to correct this

[EDIT by @kuriwaki -- add reprex]

library(dataverse)

# this works
get_dataset(dataset = "doi:10.70122/FK2/PPIAXE", server = "demo.dataverse.org")
#> Dataset (182162): 
#> Version: 1.1, RELEASED
#> Release Date: 2020-12-30T00:00:24Z
#> License: CC0
#> 22 Files:
#>                   label version      id               contentType
#> 1 nlsw88_rds-export.rds       1 1734016  application/octet-stream
#> 2            nlsw88.tab       3 1734017 text/tab-separated-values

# but not this
dataset_versions(dataset = "doi:10.70122/FK2/PPIAXE", server = "demo.dataverse.org")
#> Error: $ operator is invalid for atomic vectors

Created on 2021-01-22 by the reprex package (v0.3.0)

kuriwaki commented 3 years ago

This is still a error with v0.3.0 and I put a reprex in the original post.

kuriwaki commented 3 years ago

Fix for this seems straightforward -- do not force httr output to be as = "text". Then it renders properly. 0dc86ca (in dev)

library(dataverse)

# Only one change in dev 0dc86cac: remove "as-text" in httr::content call
dataset_versions(dataset = "doi:10.70122/FK2/PPIAXE", server = "demo.dataverse.org")
#> [[1]]
#> Version (182162): 1.1, RELEASED
#> Release Date: 2020-12-30T00:00:24Z
#> 2 Files:
#> [[1]]
#> File (1734016): nlsw88_rds-export.rds
#> Dataset version: 182162
#> MD5: b01196b9a6b302d9913d3ce5211a381a
#> Description: ID: 1734016. NLSW88 data, but read and written as a R Rds file
#> 
#> [[2]]
#> File (1734017): nlsw88.tab
#> Dataset version: 182162
#> MD5: 9664abc8f14433e212882a55fae03385
#> Description: ID: 1734017. National Longitudinal Survey of Women (NLSW) 1988 extract. Stata native dataset, originaly nlsw88.dta
#> 
#> 
#> [[2]]
#> Version (182161): 1.0, RELEASED
#> Release Date: 2020-12-29T23:58:05Z
#> 2 Files:
#> [[1]]
#> File (1734016): nlsw88_rds-export.rds
#> Dataset version: 182161
#> MD5: b01196b9a6b302d9913d3ce5211a381a
#> Description: ID: 1734016. NLSW88 data, but read and written as a R Rds file
#> 
#> [[2]]
#> File (1734017): nlsw88.tab
#> Dataset version: 182161
#> MD5: 9664abc8f14433e212882a55fae03385
#> Description: ID: 1734017. National Longitudinal Survey of Women (NLSW) 1988 extract. Stata native dataset, originaly nlsw88.dta

Created on 2021-03-02 by the reprex package (v0.3.0)