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

adding update metadata function #49

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ohcleandat
Type: Package
Title: One Health Data Cleaning and Quality Checking Package
Version: 0.3.5
Version: 0.3.6
Authors@R: c(
person("Collin", "Schwantes", email = "schwantes@ecohealthalliance.org", role = c("cre", "aut"), comment = c(ORCID = "0000-0003-4014-4896")),
person("Johana", "Teigen", email = "teigen@ecohealthalliance.org", role = "aut", comment = c(ORCID = "0000-0002-6209-2321")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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,"%>%")
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ohcleandat 0.3.6

* Adds a function to update the descriptive metadata in a frictionless datapackage

# ohcleandat 0.3.5

# ohcleandat 0.3.4
Expand Down
40 changes: 40 additions & 0 deletions R/update_frictionless_metadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Update descriptive metadata in frictionless datapackage
#'
#' This function overwrites the descriptive metadata associated with a
#' frictionless datapackage. It does *NOT* validate the metadata, or check
#' for conflicts with existing descriptive metadata. It is very easy to create
#' invalid metadata.
#'
#' @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()
}
36 changes: 36 additions & 0 deletions man/update_frictionless_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions vignettes/data_examples/my_data.csv
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions vignettes/metadata.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}


```