knitr::opts_chunk$set(echo = TRUE)
dataset_metadata <- jsonlite::read_json("dataset-metadata.json") yml_metadata <- rmarkdown::yaml_front_matter(here::here("data-raw/dataset_create.Rmd"))
dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[1]]$value <- yml_metadata$dataset$citation$title
dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[5]]$value[[1]]$dsDescriptionValue$value <- yml_metadata$dataset$citation$dsDescriptionValue
dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[6]]$value[[1]] <- yml_metadata$dataset$citation$subject
dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[2]]$value[[1]] <- yml_metadata$dataset$citation$productionDate
## Remove existing author entries dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[3]]$value <- NULL ## Add author entries num_yml_authors <- length(yml_metadata$dataset$citation$author) for (i in 1:num_yml_authors) { dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[3]]$value[[i]] <- list( authorName = list( value = yml_metadata$dataset$citation$author[[i]]$authorName, typeClass = "primitive", multiple = FALSE, typeName = "authorName" ), authorAffiliation = list( value = yml_metadata$dataset$citation$author[[i]]$authorAffiliation, typeClass = "primitive", multiple = FALSE, typeName = "authorAffiliation" ) ) }
## Remove existing contact entries dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[4]]$value <- NULL ## Add contact entries num_yml_contacts <- length(yml_metadata$dataset$citation$datasetContact) for (i in 1:num_yml_contacts) { dataset_metadata$datasetVersion$metadataBlocks$citation$fields[[4]]$value[[i]] <- list( datasetContactName = list( value = yml_metadata$dataset$citation$datasetContact[[i]]$datasetContactName, typeClass = "primitive", multiple = FALSE, typeName = "datasetContactName" ), datasetContactEmail = list( value = yml_metadata$dataset$citation$datasetContact[[i]]$datasetContactEmail, typeClass = "primitive", multiple = FALSE, typeName = "datasetContactEmail" ) ) }
## Remove existing geographic coverage entries dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[1]]$value <- NULL ## Add geographic coverage entries nms <- names(yml_metadata$dataset$geospatial$geographicCoverage) if ("country" %in% nms) { dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[1]]$value[[1]]$country <- list( typeName = "country", multiple = FALSE, typeClass = "controlledVocabulary", value = yml_metadata$dataset$geospatial$geographicCoverage$country ) } if ("state" %in% nms) { dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[1]]$value[[1]]$state <- list( typeName = "state", multiple = FALSE, typeClass = "primitive", value = yml_metadata$dataset$geospatial$geographicCoverage$state ) } if ("city" %in% nms) { dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[1]]$value[[1]]$city <- list( typeName = "city", multiple = FALSE, typeClass = "primitive", value = yml_metadata$dataset$geospatial$geographicCoverage$city ) } if ("otherGeographicCoverage" %in% nms) { dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[1]]$value[[1]]$otherGeographicCoverage <- list( typeName = "otherGeographicCoverage", multiple = FALSE, typeClass = "primitive", value = yml_metadata$dataset$geospatial$geographicCoverage$otherGeographicCoverage ) }
## Remove existing geographic unit entries dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[2]]$value <- NULL ## Add geographic unit entries geo_unit_l <- as.list(yml_metadata$dataset$geospatial$geographicUnit) dataset_metadata$datasetVersion$metadataBlocks$geospatial$fields[[2]]$value <- geo_unit_l
if (exists("data/dataset_doi")) { dataset_doi <- readLines(here::here("data/dataset_doi"))[1] if (is.na(dataset_doi)) { ## Create dataset ds_info <- dataverse::create_dataset( dataverse = "biocomplexity", body = dataset_metadata, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER") ) ## Save dataset DOI to data writeLines(ds_info$data$persistentId, here::here("data/dataset_doi")) } else { dataverse::update_dataset( dataset = dataset_doi, body = dataset_metadata, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER") ) } }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.