Skip to content

Commit

Permalink
incorporating fl metadata function into vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
collinschwantes committed Aug 28, 2024
1 parent d94489e commit 88c2513
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 61 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Imports:
arsenal,
containerTemplateUtils (>= 0.0.0.9006),
dplyr,
frictionless,
googledrive,
googlesheets4,
here,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(detect_language)
export(download_dropbox)
export(download_googledrive_files)
export(dropbox_upload)
export(expand_frictionless_metadata)
export(get_dropbox_val_logs)
export(get_odk_form_schema)
export(get_odk_responses)
Expand Down
4 changes: 2 additions & 2 deletions R/create_structural_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ create_structural_metadata <- function(data,
#' @param additional_elements data frame. OPTIONAL Empty tibble with structural
#' metadata elements and their types.
#'
#' @note See vignette on metadata for examples
#'
#' @return data.frame
#' @export
#'
#' @examples
update_structural_metadata <- function(data,metadata,primary_key = "", foreign_key = "",additional_elements = tibble::tibble()){

existing_fkeys <- metadata |>
Expand Down
3 changes: 3 additions & 0 deletions man/update_structural_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,22,"Johana","c",1
2024-08-27,94,"Collin","c",2
2024-08-28,85,"Collin","b",3
2024-08-29,63,"Collin","d",4
2024-08-30,92,"Collin","e",5
2024-08-31,8,"Collin","a",6
2024-09-01,96,"Collin","e",7
2024-09-02,53,"Johana","b",8
2024-09-03,11,"Johana","a",9
2024-09-04,97,"Johana","d",10
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
61 changes: 13 additions & 48 deletions vignettes/metadata.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ descriptive_metadata <- list (

# create a new client
cli <- deposits::depositsClient$new(service = "zenodo",
metadata = descriptive_metadata, sandbox = TRUE)
metadata = descriptive_metadata,
sandbox = TRUE)


# create a new deposit item - this creates a placeholder in zenodo
Expand All @@ -168,58 +169,22 @@ cli$deposit_new()
# this will make a datapackage.json item in data_examples
cli$deposit_add_resource(path = "data_examples/my_data.csv")

## open the

# Take a peak at the `datapackage.json` file - you'll see the first section
# describes the csv file, the second section describes the data in the csv,
# the third section contains the descriptive metadata we created

# Add in your metadata

data_package <- frictionless::read_package("data_examples/datapackage.json")

# get the schema for a resource in the data package
my_data_schema <- data_package|>
get_schema("my_data")


## build up schema based on structural metadata

for(idx in 1:length(my_data_schema$fields)){
# item to build out
x <- my_data_schema$fields[[idx]]
for(idy in 1:length(structural_metadata)){

y <- structural_metadata[idx,idy][[1]]
# get property name
property_to_add_name <- names(structural_metadata)[idy]

# skip properties that already exist
if(property_to_add_name %in% names(x)){
next()
}

property_to_add_value <- y
names(property_to_add_value) <- property_to_add_name
x <- c(x, property_to_add_value)
}

# update
my_data_schema$fields[[idx]] <- x
}

# update the datapackage.json
data_package <- data_package|>
frictionless::remove_resource("my_data") |>
frictionless::add_resource(resource_name = "my_data",
data = "data_examples/my_data.csv",
schema = my_data_schema,
)

# write the datapackage.json
frictionless::write_package(data_package,directory = "data_examples/")

# upload to zenodo - this creates a draft deposit in Zenodo
# Add your structural metadata to the frictionless metadata

expand_frictionless_metadata(structural_metadata = structural_metadata,
resource_name = "my_data", # name of the file with no extension
resource_path = "data_examples/my_data.csv",
data_package_path = "data_examples/datapackage.json")

# upload to zenodo - this creates a **draft** deposit in Zenodo
cli$deposit_upload_file(path = "data_examples/")

# there are methods for embargoing or restricting
# there are methods for embargoing or restricting deposits in {deposits}

```
2 changes: 1 addition & 1 deletion vignettes/metadata_examples/structural_metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"measurement","distance to ephemeral pan from livestock pen","meters","https://schema.org/Distance",NA,FALSE,FALSE
"measured_by","A person who measured the distance",NA,"https://schema.org/name",NA,FALSE,TRUE
"site_name","Name of site",NA,"https://schema.org/name",NA,FALSE,TRUE
"key",NA,NA,NA,NA,TRUE,FALSE
"key","unique id for each row",NA,"https://schema.org/identifier",NA,TRUE,FALSE

0 comments on commit 88c2513

Please sign in to comment.