Hi @eliansoutu, my apologies for the long delay! Thank you for your patience
(and thank you @stefanie for keeping an eye on this for me!)
I can confirm that this behaviour is happening: when you update a resource, the metadata (e.g. description) is deleted:
(note key
below is just an API key for the beta instance)
library(ckanr)
#> Loading required package: DBI
ckanr_setup("https://beta.ckan.org/")
# create package and resource
package <- package_create("ckanr-metadata-update-test", key = key)
resource <- resource_create(package[["id"]], description = "this is a resource with a description", key = key)
# check that resource has a description
resource_id <- resource[["id"]]
resource_show(resource_id)
#> <CKAN Resource> e810ca9e-880f-4213-9c52-d0538531c32d
#> Name:
#> Description: this is a resource with a description
#> Creator/Modified: 2021-10-20T18:05:45.741174 /
#> Size:
#> Format:
# prep file to upload to resource
file <- "mtcars.csv"
write.csv(mtcars, file)
# update with file
resource_update(resource_id, path = file, key = key)
#> <CKAN Resource> e810ca9e-880f-4213-9c52-d0538531c32d
#> Name:
#> Description:
#> Creator/Modified: 2021-10-20T18:05:45.741174 / 2021-10-20T18:05:46.574034
#> Size: 1783
#> Format: CSV
# Look at it again - no longer has a description (and you can see from update call above, too)
resource_show(resource_id)$description
#> NULL
# What about if you pass the description when updating?
resource_update(resource_id, path = file, key = key, extras = list(description = "this is a resource with a description"))$description
#> [1] "this is a resource with a description"
# Description sticks
It sounds like, from a previous issue (relating to updating packages, not resources, but same idea) that this behaviour is intended - the list of things to update should be “complete”, so not including metadata means the existing metadata will be removed.
So for now, I would suggest calling resource_show()
, getting any fields you want from there, and also passing those when you do resource_update()
, like this:
# Would suggest getting the resource, pulling its description (or whatever fields are needed), then passing that along with the resource_update()
resource <- resource_show(resource_id)
description <- resource$description
resource_update(resource_id, path = file, key = key, extras = list(description = description))
#> <CKAN Resource> e810ca9e-880f-4213-9c52-d0538531c32d
#> Name:
#> Description: this is a resource with a description
#> Creator/Modified: 2021-10-20T18:05:45.741174 / 2021-10-20T18:05:48.196164
#> Size: 1783
#> Format: CSV
I understand that this is not clear in the documentation, as it says “Other metadata, such as name or description, are not updated.” - but it seems quite the opposite is true!
I will follow up in the issue I linked, since it looks like the intention was to update the documentation for package_update()
, so maybe we can update for resource_update()
at the same time to clarify what the actual behaviour is.
I hope this is helpful, please let me know if you have any more questions!