Skip to content

Commit

Permalink
update function and argument names to snake-case (#15)
Browse files Browse the repository at this point in the history
* add testthat for unit testing

* add testthat for unit testing

* update function names to tidyverse style guide: public functions in snake case. Private functions prefixed by .

* update function name and documentation conform to tidyverse snake case style guide

* remove old function name man files

* initial commit snake case function naming

* snake case function naming initial commit

* remove old function name man files

* initial commit snake case function names

* set_DOI to set_doi

* set_DOI to set_doi

* write.readMe to write_readme

* arguments to snake case

* arguments to snake case

* arguments to snake case

* set_DOI to set_doi

* delete man file for old read me function name

* write_readme initial commit

* Version to 0.0.1.1 - all function and argument names changed to snake case.
  • Loading branch information
RobLBaker authored Oct 25, 2022
1 parent c5dc121 commit 892bf78
Show file tree
Hide file tree
Showing 53 changed files with 1,444 additions and 811 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: EMLeditor
Title: View and Edit EML
Version: 0.0.1.0
Version: 0.0.1.1
Authors@R:
person("Robert", "Baker", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7591-5035"))
Expand All @@ -25,3 +25,6 @@ Imports:
ISOcodes,
crayon,
dplyr
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
56 changes: 26 additions & 30 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
# Generated by roxygen2: do not edit by hand

export(get.CUI)
export(get.DOI)
export(get.DRRdoi)
export(get.DSRefID)
export(get.abstract)
export(get.authorList)
export(get.beginDate)
export(get.citation)
export(get.endDate)
export(get.fileInfo)
export(get.lit)
export(get.parkUnits)
export(get.producingUnits)
export(get.title)
export(get.unitPolygon)
export(new.DOI)
export(set.CUI)
export(set.DOI)
export(set.DRRdoi)
export(set.NPSpublisher)
export(set.abstract)
export(set.forByNPS)
export(set.language)
export(set.lit)
export(set.parkUnits)
export(set.producingUnits)
export(set.protocol)
export(set.title)
export(set.version)
export(write.readMe)
export(get_abstract)
export(get_author_list)
export(get_begin_date)
export(get_citation)
export(get_cui)
export(get_doi)
export(get_drr_doi)
export(get_ds_id)
export(get_end_date)
export(get_file_info)
export(get_lit)
export(get_park_units)
export(get_producing_units)
export(get_title)
export(new_doi)
export(set_abstract)
export(set_cui)
export(set_doi)
export(set_drr_doi)
export(set_language)
export(set_lit)
export(set_park_units)
export(set_producing_units)
export(set_protocol)
export(set_title)
export(write_readme)
importFrom(magrittr,"%>%")
321 changes: 159 additions & 162 deletions R/editEMLfunctions.R

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions R/getEMLfunctions.R

Large diffs are not rendered by default.

75 changes: 35 additions & 40 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#' inject NPS Publisher info into metadata
#'
#' @description injects static NPS-specific publisher info into eml documents. Calls the sub-function set.forOrByNPS, which adds an additionalMetadata element with for or by NPS = TRUE.
#' @description .set_npspublisher injects static NPS-specific publisher info into eml documents. Calls the sub-function set.forOrByNPS, which adds an additionalMetadata element with for or by NPS = TRUE.
#'
#' @details checks to see if the publisher element exists, and if not injects NPS-specific info into EML such as publisher, publication location, and ROR id - the types of things that will be the same for all NPS data or non-data publications and do not require user input. This function will be embedded in all set. and write. class functions (and get. functions?).
#'
#' @param emlObject is an R object imported (typically from an EML-formatted .xml file) using EmL::read_eml(<filename>, from="xml").
#' @param eml_object is an R object imported (typically from an EML-formatted .xml file) using EmL::read_eml(<filename>, from="xml").
#'
#' @return emlObject
#' @export
#' @return eml_object
#'
#' @examples
#' \dontrun{
#' set.NPSpublisher(emlObject)
#' .set_npspublisher(eml_object)
#' }
set.NPSpublisher<-function(emlObject){
.set_npspublisher<-function(eml_object){
#get existing publisher info for the data package:
publish<-emlObject$dataset$publisher
publish<-eml_object$dataset$publisher

#create desired publisher info:
pubset<- list(organizationName =
Expand All @@ -31,31 +30,30 @@ set.NPSpublisher<-function(emlObject){

#if existing and desired publisher don't match, replace existing with desired.
if(!identical(publish, pubset)){
emlObject$dataset$publisher<-pubset
eml_object$dataset$publisher<-pubset
}

#since the publisher is NPS, sets an additionalMetadata field for For or By NPS to TRUE.
emlObject<-set.forByNPS(emlObject)
eml_object<-.set_for_by_nps(eml_object)

return(emlObject)
return(eml_object)
}

#' Add/update EMLeditor version
#'
#' @description set.version adds the current version of EMLeditor to the EML document.
#' @description .set_version adds the current version of EMLeditor to the EML document.
#'
#' @details set.version adds the current version of EMLeditor to the metadata, specifically in the "additionalMetadata" element
#' @details .set_version adds the current version of EMLeditor to the metadata, specifically in the "additionalMetadata" element
#'
#' @param emlObject is an R object imported (typically from an EML-formatted .xml file) using EML::read_eml(<filename>, from="xml").
#' @param eml_object is an R object imported (typically from an EML-formatted .xml file) using EML::read_eml(<filename>, from="xml").
#'
#' @return emlObject
#' @export
#' @return eml_object
#'
#' @examples
#' \dontrun{
#' set.version(emlObject)
#' .set_version(eml_object)
#' }
set.version<-function(emlObject){
.set_version<-function(eml_object){
#get current EMLeditor package version:
currentvers<-as.character(utils::packageVersion("EMLeditor"))

Expand All @@ -66,11 +64,11 @@ set.version<-function(emlObject){
id="emlEditor")

#access additionalMetadata elements:
addMeta<-EML::eml_get(emlObject, "additionalMetadata")
addMeta<-EML::eml_get(eml_object, "additionalMetadata")

#if no additionalMetadata, add in EMLeditor and current version:
if(sum(names(addMeta)!="@context")==0){
emlObject$additionalMetadata<-EMLed
eml_object$additionalMetadata<-EMLed
}

#if there are existing additionalMetadata elements:
Expand All @@ -96,34 +94,33 @@ set.version<-function(emlObject){
#if no info on EMLeditor, add EMLeditor to additionalMetadata
if(is.null(app)){
if(x==1){
emlObject$additionalMetadata<-list(EMLed, emlObject$additionalMetadata)
eml_object$additionalMetadata<-list(EMLed, eml_object$additionalMetadata)
}
if(x>1){
emlObject$additionalMetadata[[x+1]]<-EMLed
eml_object$additionalMetadata[[x+1]]<-EMLed
}
}
}
return(emlObject)
return(eml_object)
}

#' Get Park Unit Polygon
#'
#' @description get.unitPolygon gets the polygon for a given park unit.
#' @description .get_unit_polygon gets the polygon for a given park unit.
#'
#' @details retrieves a geoJSON string for a polygon of a park unit from NPS Rest services. Note: This is not the official boundary (erm... ok then what is it?!?).
#'
#' @param Unit_Code a string (typically 4 characters) that is the park unit code.
#' @param unit_code a string (typically 4 characters) that is the park unit code.
#'
#' @return a park polygon
#' @export
#'
#' @examples
#' \dontrun{
#' poly<-get.unitPolygon("BICY")
#' poly<-.get_unit_polygon("BICY")
#' }
get.unitPolygon <- function(Unit_Code) {
.get_unit_polygon <- function(unit_code) {
# get geography from NPS Rest Services
UnitsURL <- paste0("https://irmaservices.nps.gov/v2/rest/unit/", Unit_Code, "/geography")
UnitsURL <- paste0("https://irmaservices.nps.gov/v2/rest/unit/", unit_code, "/geography")
xml <- httr::content(httr::GET(UnitsURL))

# Create spatial feature from polygon info returned from NPS
Expand All @@ -134,19 +131,17 @@ get.unitPolygon <- function(Unit_Code) {

#' Set "For or By" NPS
#'
#' @description set.forByNPS adds an element to additionalMetadata with For or By NPS set to TRUE and a second element agencyOriginated set to "NPS" with the understanding that all data products created for or by the NPS have NPS as the originating agency.
#' @description .set_for_by_nps adds an element to additionalMetadata with For or By NPS set to TRUE and a second element agencyOriginated set to "NPS" with the understanding that all data products created for or by the NPS have NPS as the originating agency.
#'
#' @param emlObject is an R object imported (typically from an EML-formatted .xml file) using EML::read_eml(<filename>, from="xml").
#' @param eml_object is an R object imported (typically from an EML-formatted .xml file) using EML::read_eml(<filename>, from="xml").
#'
#' @return emlObject
#'
#' @export
#' @return eml_object
#'
#' @examples
#' \dontrun{
#' set.forByNPS(emlObject)
#' .set_for_by_nps(eml_object)
#' }
set.forByNPS<-function(emlObject){
.set_for_by_nps<-function(eml_object){

#set up additionalMetadata elements for EMLeditor:
forby<-list(metadata=list(agencyOriginated=list(
Expand All @@ -155,12 +150,12 @@ set.forByNPS<-function(emlObject){
id="agencyOriginated"))

#access additionalMetadata elements:
addMeta<-EML::eml_get(emlObject, "additionalMetadata")
addMeta<-EML::eml_get(eml_object, "additionalMetadata")
addMeta<-within(addMeta, rm('@context'))

#if no additionalMetadata, add in EMLeditor and current version:
if(length(names(addMeta))==0){
emlObject$additionalMetadata<-forby
eml_object$additionalMetadata<-forby
}

#if there are existing additionalMetadata elements:
Expand All @@ -178,12 +173,12 @@ set.forByNPS<-function(emlObject){
#if no info on ForOrByNPS, add ForOrByNPS to additionalMetadata
if(is.null(For_or_by_NPS)){
if(x==1){
emlObject$additionalMetadata<-list(forby, emlObject$additionalMetadata)
eml_object$additionalMetadata<-list(forby, eml_object$additionalMetadata)
}
if(x>1){
emlObject$additionalMetadata[[x+1]]<-forby
eml_object$additionalMetadata[[x+1]]<-forby
}
}
}
return(emlObject)
return(eml_object)
}
32 changes: 16 additions & 16 deletions R/writeReadMe.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#' Writes a README file
#'
#' @description write.readMe writes a readme file based on the current metadata
#' @description write_readme writes a readme file based on the current metadata
#'
#' @details write.readMe writes a mock-up of the readme file that will eventually be automatically generated by DataStore. This file is for error checking purposes only. If something looks off, you can go back and fix your metadata to correct it but you should not upload this readme file with your data package.
#' @details write_readme writes a mock-up of the readme file that will eventually be automatically generated by DataStore. This file is for error checking purposes only. If something looks off, you can go back and fix your metadata to correct it but you should not upload this readme file with your data package.
#'
#' @param emlObject is an R object imported (typically from an EML-formatted .xml file) using EML::read_eml(<filename>, from="xml").
#' @param eml_object is an R object imported (typically from an EML-formatted .xml file) using EML::read_eml(<filename>, from="xml").
#' @param outfile is the name of the file you want to write, typically *.txt.
#'
#' @return a character sting in readable format (saved to the given outfile)
#' @export
#'
#' @examples
#' \dontrun{
#' write.readMe(emlObject, "TestReadMe.txt")
#' write_readme(eml_object, "TestReadMe.txt")
#' }
write.readMe<-function(emlObject, outfile){
write_readme<-function(eml_object, outfile){

#get components:
Ref<-get.DSRefID(emlObject) #Data Store Ref. ID
doi<-get.DOI(emlObject) #DOI
title<-get.title(emlObject) #title
abstract<-get.abstract(emlObject) #abstract
fileInfo<-get.fileInfo(emlObject) #names, sizes, descriptions
start<-get.beginDate(emlObject) #content start date
end<-get.endDate(emlObject) #content end date
units<-get.parkUnits(emlObject) #park units where data were collected
CUI<-get.CUI(emlObject) #controlled unclassified information status
DRRdoi<-get.DRRdoi(emlObject) #DOI of accompanying DRR
citation<-get.citation(emlObject) #citation
Ref<-get_ds_id(eml_object) #Data Store Ref. ID
doi<-get_doi(eml_object) #DOI
title<-get_title(eml_object) #title
abstract<-get_abstract(eml_object) #abstract
fileInfo<-get_file_info(eml_object) #names, sizes, descriptions
start<-get_begin_date(eml_object) #content start date
end<-get_end_date(eml_object) #content end date
units<-get_park_units(eml_object) #park units where data were collected
CUI<-get_cui(eml_object) #controlled unclassified information status
DRRdoi<-get_drr_doi(eml_object) #DOI of accompanying DRR
citation<-get_citation(eml_object) #citation

#Write to the components to the text file specified in "outfile".
cat(paste0("ReadMe file for DataStore reference# ", Ref), file=outfile, sep="\n")
Expand Down
12 changes: 6 additions & 6 deletions man/get.unitPolygon.Rd → man/dot-get_unit_polygon.Rd

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

22 changes: 22 additions & 0 deletions man/dot-set_for_by_nps.Rd

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

14 changes: 7 additions & 7 deletions man/set.NPSpublisher.Rd → man/dot-set_npspublisher.Rd

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

Loading

0 comments on commit 892bf78

Please sign in to comment.