From 4ccfec8eeffa7d41348b8ce3a62f9e6a6b511f92 Mon Sep 17 00:00:00 2001 From: Collin Schwantes Date: Wed, 4 Sep 2024 12:36:31 -0600 Subject: [PATCH] adding update metadata function --- NAMESPACE | 1 + R/update_frictionless_metadata.R | 35 +++++++++++++++++++++++++++++ man/update_frictionless_metadata.Rd | 33 +++++++++++++++++++++++++++ vignettes/data_examples/my_data.csv | 20 ++++++++--------- vignettes/metadata.Rmd | 16 +++++++++++++ 5 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 R/update_frictionless_metadata.R create mode 100644 man/update_frictionless_metadata.Rd diff --git a/NAMESPACE b/NAMESPACE index c5441a1..2191136 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,6 +31,7 @@ export(read_excel_all_sheets) export(read_googlesheets) export(remove_deletions) export(set_diff) +export(update_frictionless_metadata) export(update_structural_metadata) export(validation_checks) importFrom(dplyr,"%>%") diff --git a/R/update_frictionless_metadata.R b/R/update_frictionless_metadata.R new file mode 100644 index 0000000..ab5fc5f --- /dev/null +++ b/R/update_frictionless_metadata.R @@ -0,0 +1,35 @@ +#' Title +#' +#' @param descriptive_metadata List of descriptive metadata terms. +#' @param data_package_path Character. Path to datapackage.json file +#' +#' @return invisibly writes datapackage.json +#' @export +#' +#' @examples +#' \dontrun{ +#' descriptive_metadata <- list ( +#' title = "Example Dataset", +#' description = "This is the abstract but it needs more detail", +#' creator = list (list (name = "A. Person"), list (name = "B. Person"), +#' list (name = "C. Person"),list (name = "F. Person")) +#' # , accessRights = "open" +#' ) +#' update_frictionless_metadata(descriptive_metadata = descriptive_metadata, +#' data_package_path = "data_examples/datapackage.json" +#' ) +#' } +update_frictionless_metadata <- function(descriptive_metadata, + data_package_path){ + + data_package <- frictionless::read_package(data_package_path) + + data_package_dir <- dirname(data_package_path) + + data_package$metadata <- descriptive_metadata + + # write the datapackage.json + frictionless::write_package(data_package,directory = data_package_dir) + + invisible() +} diff --git a/man/update_frictionless_metadata.Rd b/man/update_frictionless_metadata.Rd new file mode 100644 index 0000000..66e662d --- /dev/null +++ b/man/update_frictionless_metadata.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update_frictionless_metadata.R +\name{update_frictionless_metadata} +\alias{update_frictionless_metadata} +\title{Title} +\usage{ +update_frictionless_metadata(descriptive_metadata, data_package_path) +} +\arguments{ +\item{descriptive_metadata}{List of descriptive metadata terms.} + +\item{data_package_path}{Character. Path to datapackage.json file} +} +\value{ +invisibly writes datapackage.json +} +\description{ +Title +} +\examples{ +\dontrun{ +descriptive_metadata <- list ( +title = "Example Dataset", +description = "This is the abstract but it needs more detail", +creator = list (list (name = "A. Person"), list (name = "B. Person"), +list (name = "C. Person"),list (name = "F. Person")) +# , accessRights = "open" +) +update_frictionless_metadata(descriptive_metadata = descriptive_metadata, + data_package_path = "data_examples/datapackage.json" +) +} +} diff --git a/vignettes/data_examples/my_data.csv b/vignettes/data_examples/my_data.csv index 5386d82..23380b0 100644 --- a/vignettes/data_examples/my_data.csv +++ b/vignettes/data_examples/my_data.csv @@ -1,11 +1,11 @@ "date","measurement","measured_by","site_name","key" -2024-08-26,29,"Johana","b",1 -2024-08-27,53,"Johana","e",2 -2024-08-28,71,"Johana","d",3 -2024-08-29,43,"Collin","e",4 -2024-08-30,93,"Johana","b",5 -2024-08-31,4,"Collin","d",6 -2024-09-01,74,"Johana","e",7 -2024-09-02,13,"Johana","c",8 -2024-09-03,46,"Johana","e",9 -2024-09-04,44,"Collin","a",10 +2024-08-26,38,"Collin","b",1 +2024-08-27,64,"Johana","a",2 +2024-08-28,94,"Johana","e",3 +2024-08-29,75,"Johana","a",4 +2024-08-30,49,"Collin","d",5 +2024-08-31,78,"Collin","d",6 +2024-09-01,93,"Johana","b",7 +2024-09-02,2,"Johana","c",8 +2024-09-03,91,"Johana","c",9 +2024-09-04,27,"Johana","a",10 diff --git a/vignettes/metadata.Rmd b/vignettes/metadata.Rmd index 31d6151..397be23 100644 --- a/vignettes/metadata.Rmd +++ b/vignettes/metadata.Rmd @@ -185,9 +185,25 @@ expand_frictionless_metadata(structural_metadata = structural_metadata, resource_path = "data_examples/my_data.csv", data_package_path = "data_examples/datapackage.json") + +## OOPs actually I need to add more to the description + +descriptive_metadata <- list ( + title = "Example Dataset", + description = "This is the abstract but it needs more detail", + creator = list (list (name = "A. Person"), list (name = "B. Person"),list (name = "C. Person"),list (name = "F. Person")) + # , accessRights = "open" +) +update_frictionless_metadata(descriptive_metadata = descriptive_metadata, + data_package_path = "data_examples/datapackage.json" +) + +cli$deposit_fill_metadata(descriptive_metadata) +# update deposit hangs if the descriptive metadata is not properly formatted, even after correction # upload to zenodo - this creates a **draft** deposit in Zenodo cli$deposit_upload_file(path = "data_examples/") # there are methods for embargoing or restricting deposits in {deposits} + ```