# NOT RUN {
ckanr_setup(url = "https://demo.ckan.org/", key = getOption("ckan_demo_key"))
# Get file
path <- system.file("examples", "actinidiaceae.csv", package = "ckanr")
# Create package, then a resource within that package
(res <- package_create("newpackage10"))
(xx <- resource_create(package_id = res$id,
description = "my resource",
name = "bears",
upload = path,
rcurl = "http://google.com"
))
# Modify dataset, here lowercase strings in one column
dat <- read.csv(path, stringsAsFactors = FALSE)
dat$Family <- tolower(dat$Family)
newpath <- tempfile(fileext = ".csv")
write.csv(dat, file = newpath, row.names = FALSE)
# Upload modified dataset
## Directly from output of resource_create
resource_update(xx, path=newpath)
## or from the resource id
resource_update(xx$id, path=newpath)
#######
# Using default settings
ckanr_setup(url = "http://demo.ckan.org/", key = "my-demo-ckan-org-api-key")
path <- system.file("examples", "actinidiaceae.csv", package = "ckanr")
resource_update(id="an-existing-resource-id", path = path)
# Using an R object written to a tempfile, and implicit CKAN URL and API key
write.csv(data <- installed.packages(), path <- tempfile(fileext = ".csv"))
ckanr_setup(url = "http://demo.ckan.org/", key = "my-demo-ckan-org-api-key")
resource_update(id="an-existing-resource-id", path = path)
# Testing: see ?ckanr_setup to set default test CKAN url, key, package id
ckanr_setup(test_url = "http://my-ckan.org/",
test_key = "my-ckan-api-key",
test_did = "an-existing-package-id",
test_rid = "an-existing-resource-id")
resource_update(id = get_test_rid(),
path = system.file("examples",
"actinidiaceae.csv",
package = "ckanr"),
key = get_test_key(),
url = get_test_url())
# other file formats
## html
path <- system.file("examples", "mapbox.html", package = "ckanr")
# Create package, then a resource within that package
(res <- package_create("mappkg"))
(xx <- resource_create(package_id = res$id,
description = "a map, yay",
name = "mapyay",
upload = path,
rcurl = "http://google.com"
))
browseURL(xx$url)
# Modify dataset, here lowercase strings in one column
dat <- readLines(path)
dat <- sub("-111.06", "-115.06", dat)
newpath <- tempfile(fileext = ".html")
cat(dat, file = newpath, sep = "\n")
# Upload modified dataset
## Directly from output of resource_create
(xxx <- resource_update(xx, path=newpath))
browseURL(xxx$url)
# }
Run the code above in your browser using DataLab