New package: ckanr

We’re happy to finally release the first version to CRAN of ckanr

ckanr is an R client for CKAN.

For those not familiar, CKAN is an open-source data portal platform. After installation, check out ckanr::servers() for a list of instances, or the webpage http://ckan.org/instances/

You can work with local or remote CKAN instances, create and update datasets and resources, manage users, tags, and organizations, and more.

on CRAN: CRAN - Package ckanr (binaries soon)
on GitHub: https://github.com/ropensci/ckanr
README help: https://github.com/ropensci/ckanr#ckanr

It’s being developed with some awesome folks:

2 Likes

How/when are ckan instances added to ckanr so that they appear in the output of the servers() function? I was expecting to find data.gov in the listing as it is included in the ckan.org census but did not.

They are added to the servers() function manually. That is simply a function that returns a list, see https://github.com/ropensci/ckanr/blob/master/R/servers.R

I think you are looking for http://catalog.data.gov/ (which is the first result in servers()) - is that right?

I should add that these URLs are (hopefully) the base URLs for the CKAN instance - which can vary quite a bit from instance to instance

1 Like

Yes, apologize for being blind :slight_smile: Didn’t realize that it would be prefixed with catalog. Thanks.

@mihiriyer Hmmm, playing with the pkg to make sure that works, and sometimes it does, but sometimes not. It seems from

ckan_info(url = "http://catalog.data.gov/")$ckan_version
#> [1] "2.1a"

they are using a quite old CKAN version, which leads to some problems, e.g,.

package_list(url = "http://catalog.data.gov")
#> Error: 400 - Search Query Error
#>  message Search Query is invalid: "Invalid search parameters: ['limit', 'offset']"

At least there’s an informative message :slight_smile:

But we can fix that by not passing those limit and offset params, but I’d need to change that internally. Will push a fix soon. After the fix install from github like devtools::install_github("ropensci/ckanr")

issue opened https://github.com/ropensci/ckanr/issues/72

@sckott What are the implications of receiving a message such as below:

ckan_info(url = "https://inventory.data.gov/")$ckan_version
Error: lexical error: invalid char in json text.
                                       <!DOCTYPE html> <!--[if IE 7]> 
                     (right here) ------^

I also verified (View Page Info) the ckan version for this site which is 2.5.1. Let me know if you have any ideas, thanks.

thanks for the question @mihiriyer

looks like that CKAN instance requires login, simple auth with username/password

I guess we currently don’t allow you to pass in curl options to that function, but you can to i think almost all others - where you would do

ckanr::package_list("https://inventory.data.gov", httr::authenticate(user = "your username", password = "your password"))

We should make sure to allow that for all functions.

let me know if that works

Thanks for the tip @sckott. This is what I got:

Error in vapply(elements, encode, character(1)) :
values must be length 1,
but FUN(X[[2]]) result is length 7

Do you think I need to use the “type” option in the authenticate function?

that’s the error you got after executing what?

after executing the following as you mentioned in you previous reply:

ckanr::package_list(“https://inventory.data.gov”, httr::authenticate(user = “your username”, password = “your password”))

sorry, that should have been

ckanr::package_list("https://inventory.data.gov", config = httr::authenticate(user = "your username", password = "your password"))

where you need to pass it to config param

that will still error, giving

#>  Error: 409 - Validation Error
#>    offset Invalid integer 

which i’m still working out

1 Like