write_package: export optional resource properties to .json #159
-
Thank you for this package. I am using it to create frictionless datapackages for publication, and it is saving me a lot of time. My question is around adding optional properties, such as title and description. I can add these at the datapackage and at the field level and they appear in the .json export. However, when I add these at the resource level, they appear in the datapackage structure, but do not get exported to the .json file. Assuming that there is not an error with my code, is this planned behaviour? Is there a reason why optional fields can't be exported for resources like they are for the datapackage and for the resource fields? Reprex and datapackage.json file as an attachment: 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)
#> List of 5
#> $ profile : chr "tabular-data-package"
#> $ resources :List of 1
#> ..$ :List of 6
#> .. ..$ name : chr "ages"
#> .. ..$ data :'data.frame': 5 obs. of 2 variables:
#> .. .. ..$ Name: chr [1:5] "Jon" "Bill" "Maria" "Ben" ...
#> .. .. ..$ Age : num [1:5] 23 41 32 58 26
#> .. ..$ profile : chr "tabular-data-resource"
#> .. ..$ schema :List of 1
#> .. .. ..$ fields:List of 2
#> .. .. .. ..$ :List of 4
#> .. .. .. .. ..$ name : chr "Name"
#> .. .. .. .. ..$ type : chr "string"
#> .. .. .. .. ..$ title : chr "Name"
#> .. .. .. .. ..$ description: chr "Person's name"
#> .. .. .. ..$ :List of 4
#> .. .. .. .. ..$ name : chr "Age"
#> .. .. .. .. ..$ type : chr "number"
#> .. .. .. .. ..$ title : chr "Age"
#> .. .. .. .. ..$ description: chr "Person's age"
#> .. ..$ title : chr "Names and ages"
#> .. ..$ description: chr "Table showing names and ages of participants"
#> $ directory : chr "."
#> $ title : chr "Data package title"
#> $ description: chr "Data package description"
write_package(
datapackage,
directory = getwd()
) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for reporting! There is no error in your code: Question: |
Beta Was this translation helpful? Give feedback.
Thanks for reporting! There is no error in your code:
title
anddescription
are indeed not retained for new resources. I think this behaviour should change and I have created an issue to implement this as part of the next version offrictionless
: #160Question:
title
anddescription
are properties defined in the Data Resource spec. Are you ever adding properties not defined in the spec?