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

Retain resource title and description #160

Closed
peterdesmet opened this issue Oct 23, 2023 · 0 comments · Fixed by #195
Closed

Retain resource title and description #160

peterdesmet opened this issue Oct 23, 2023 · 0 comments · Fixed by #195
Labels
function:write_package Function write_package()
Milestone

Comments

@peterdesmet
Copy link
Member

peterdesmet commented Oct 23, 2023

Reported at #159: title and description for a new resource are not retained when writing a package. This is caused by:

# Save schema and reassign all resource properties (in correct order)
# This also removes $data and $read_from
schema <- resource$schema
resource <- list(
name = resource_name,
path = file_name,
profile = "tabular-data-resource",
# title: not set
# description: not set
format = "csv",
mediatype = "text/csv",
encoding = "utf-8", # Enforced by readr::write_csv()
# dialect: not set, default
# bytes: not set
# hash: not set
# sources: not set
# licenses: not set
schema = schema
)

This behaviour should change, so that a custom provided title and description are retained. They won't ever conflict with any of the information set by write_resource() (in contrast with e.g. bytes). Alternatively, this could be expanded to any custom property (not only title and description, but that is slightly harder to implement.

Test with:

library(tidyverse)
library(frictionless)

# Make df
Name <- c("Jon", "Bill", "Maria", "Ben", "Tina")
Age <- c(23, 41, 32, 58, 26)
df <- data.frame(Name, Age)

datapackage <-
  create_package() %>%
  add_resource(
    resource_name = "ages", 
    data = df
  )

# Add descriptors at the datapackage level
datapackage$title <- "Data package title" #
datapackage$description <- "Data package description" #

# Add descriptors at the column level
datapackage$resources[[1]]$schema$fields[[1]]$title <- "Name" #
datapackage$resources[[1]]$schema$fields[[1]]$description <- "Person's name" #
datapackage$resources[[1]]$schema$fields[[2]]$title <- "Age" #
datapackage$resources[[1]]$schema$fields[[2]]$description <- "Person's age" #

# Add descriptors at the resource level
datapackage$resources[[1]]$title <- "Names and ages" #
datapackage$resources[[1]]$description <- "Table showing names and ages of participants" #

str(datapackage)
write_package(datapackage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function:write_package Function write_package()
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant