Skip to content

Commit

Permalink
Add taxonomic coverage and EML version to summary metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
drkrynstrng committed Dec 4, 2018
1 parent 03dda4d commit 437b698
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^LICENSE$
^inst/Pres$
33 changes: 24 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@ Authors@R: c(
person("Irene", "Steves", comment = "https://github.com/isteves", role = "aut"),
person("Mitchell", "Maier", email = "[email protected]", role = "aut"))
Maintainer: Julien Brun <[email protected]>
Description: Tools to download data and metadata from DataONE (https://www.dataone.org) and load this information in R.
Description: Tools to download data and metadata from DataONE (https://www.dataone.org) and load this information in R.
License: Apache License (== 2.0)
RoxygenNote: 6.1.1
Imports: dataone, dplyr, eml2, emld, lubridate, purrr, readr, stats, stringr, tibble, tidyr
Remotes: cboettig/eml2,
cboettig/emld,
DataONEorg/rdataone
Suggests: testthat,
URL: https://github.com/nceas/metajam
BugReports: https://github.com/nceas/metajam/issues
Imports:
dataone,
dplyr,
eml2,
emld,
lubridate,
purrr,
readr,
stats,
stringr,
tibble,
tidyr
Remotes:
cboettig/eml2,
cboettig/emld,
DataONEorg/rdataone
Suggests:
testthat,
knitr,
rmarkdown,
udunits2
Encoding: UTF-8
VignetteBuilder: knitr
URL: https://github.com/nceas/metajam
BugReports: https://github.com/nceas/metajam/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import(readr)
import(stringr)
import(tidyr)
importFrom(dataone,CNode)
importFrom(dataone,getSystemMetadata)
importFrom(dataone,query)
importFrom(emld,as_emld)
importFrom(lubridate,ymd_hms)
importFrom(purrr,"%||%")
importFrom(stats,setNames)
importFrom(stringr,str_trim)
importFrom(tibble,enframe)
importFrom(utils,URLdecode)
importFrom(utils,write.csv)
47 changes: 24 additions & 23 deletions R/check_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,74 @@
#'
#' This function takes an identifier and checks to see if it has been obsoleted.
#'
#' @param pid (character) The persistent identifier of a data, metadata, or resource map object on a DataONE member node
#' @param formatType (character) Optional. The format type to return (DATA, METADATA, RESOURCE)
#' @param pid (character) The persistent identifier of a data, metadata, or resource map object on a DataONE member node.
#' @param formatType (character) Optional. The format type to return (DATA, METADATA, RESOURCE).
#'
#' @importFrom dataone CNode getSystemMetadata
#' @import stringr
#' @return A data.frame of object version PIDs and related information.
#'
#' @import dataone
#' @import dplyr
#' @import stringr
#'
#' @export
#'
#' @examples
#' \dontrun{
#' # Most data URL's and identifiers work
#' check_version("https://cn.dataone.org/cn/v2/resolve/urn:uuid:a2834e3e-f453-4c2b-8343-99477662b570")
#'
#'
#' # Returns a warning if several identifiers are returned:
#' check_version(
#' "https://pasta.lternet.edu/package/data/eml/edi/195/2/51abf1c7a36a33a2a8bb05ccbf8c81c6"
#' )
#' check_version("doi:10.18739/A2ZF6M")
#'
#'
#' # You can specify a formatType (metadata, data, resource)
#' check_version("doi:10.18739/A2ZF6M", formatType = "metadata")
#'
#'
#' # Returns a warning if the identifier has been obsoleted
#' check_version("doi:10.18739/A2HF7Z", formatType = "metadata")
#'
#'
#' # Returns an error if no matching identifiers are found
#' check_version("a_test_pid")
#' }
#'

check_version <- function(pid, formatType = NULL){
check_version <- function(pid, formatType = NULL) {

# check that pid is of type character
if (!all(is.character(pid), all(nchar(pid) > 0))) {
stop("Argument 'pids' must be character class with non-zero number of characters.")
}
while(nchar(pid) > 5) {

while (nchar(pid) > 5) {
results <- suppressMessages(
dataone::query(dataone::CNode(),
list(q = sprintf('identifier:"%s"', pid),
fl = "identifier, dateUploaded, formatType, obsoletedBy, resourceMap"),
as = "data.frame")
)
#if results is null or empty dataframe, remove part of the URI
#if results is null or empty dataframe, remove part of the URI
if (is.null(results) || nrow(results) == 0) {
pid <- gsub("^[^/=]+[/=]*", "", pid)

} else {
#what to do if multiple are returned
break
}
}
if(nrow(results) == 0){

if (nrow(results) == 0) {
stop("No matching identifiers were found.")
}

# filter out extra types (resource map/etc with similar pid)
if(!is.null(formatType)){
if (!is.null(formatType)) {
formatType <- toupper(formatType)
results <- results[results$formatType == formatType,]
}
if(nrow(results) == 1){
if(is.null(results$obsoletedBy) || is.na(results$obsoletedBy)){

if (nrow(results) == 1) {
if (is.null(results$obsoletedBy) || is.na(results$obsoletedBy)) {
message("\n",
results$identifier,
"\nis the latest version for identifier\n",
Expand All @@ -79,6 +80,6 @@ check_version <- function(pid, formatType = NULL){
} else {
warning("Several identifiers are associated with ", pid)
}

return(results)
}
Loading

0 comments on commit 437b698

Please sign in to comment.