Skip to content

Commit e2310f7

Browse files
authoredJan 22, 2025
Merge pull request nationalparkservice#64 from RobLBaker/master
Version 1.0.0
2 parents 4a79c35 + ed26fc7 commit e2310f7

40 files changed

+117
-230
lines changed
 

‎DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: NPSutils
22
Type: Package
33
Title: Collection of Functions to read and manipulate information from the NPS DataStore
4-
Version: 0.3.2
4+
Version: 1.0.0
55
Authors@R: c(
66
person(given = "Robert", family = "Baker", email = "robert_baker@nps.gov",
77
role = c("aut", "cre"),

‎NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export(get_unit_code_info)
1818
export(get_unit_info)
1919
export(load_core_metadata)
2020
export(load_data_package)
21-
export(load_data_package_deprecated)
2221
export(load_data_packages)
2322
export(load_pkg_metadata)
2423
export(map_wkt)

‎NEWS.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# NPSutils 0.3.3 (under development)
1+
# NPSutils 1.0.0
2+
## 2025-12-19
3+
* remove `get_data_packages_deprecated()` is a breaking change resulting in release of v.1.0.0.
4+
* update documentation for `get_unit_code()`, `get_park_code()`, and `get_unit_code_info()`
25

3-
##2024-12-19
6+
## 2024-12-19
47
* remove `validate_data_package()` as this function was listed as "still under construction" is mostly obsolete given other functions and functions in the DPchecker package.
58
* remove `load_domains()` as this function was not working properly and was conceived of before the data package specifications were properly set.
69
## 2024-12-19

‎NPSutils.Rproj

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 68a3c096-553f-4a8e-8ad4-78954075e8ec
23

34
RestoreWorkspace: Default
45
SaveWorkspace: Default

‎R/getParkUnitInfo.R

+36-43
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#' Dynamically access NPS park unit code data
33
#'
4-
#' @description \code{get_unit_code} accesses info from irmaservices.nps.gov. Search for park or park unit with any string and return all applicable UnitCodes. Handy for use with get.dataPackage if you don't know a Park's UnitCode. allows the user to access information based on park codes
4+
#' @description Accesses info from irmaservices.nps.gov. Search for park or park unit with any string and return all applicable UnitCodes.
55
#'
66
#' @details Contains multiple somewhat redundant functions for searching park units including unit codes, names, states, regions, networks, regions, etc.
77
#' These functions can be handy if you need to supply the unit code when downloading data but only know the park name, if you have a unit code but don't know what park, region, etc it refers to, or if you want to know all the parks that are within a given network, region, or state (note: it will actually supply all park units, not just National Parks).
@@ -11,7 +11,7 @@
1111
#'
1212
#' @importFrom magrittr %>%
1313
#'
14-
#' @return one data frame to the global environment. May contain multiple matches. Sufficient detail should be provided to choose the appropriate UnitCode for use with other NPSutils functions such as get.parkTaxonReferences (in get.referenceInfo.R).
14+
#' @return one data frame to the global environment. May contain multiple matches.
1515
#'
1616
#' @export
1717
#' @examples
@@ -22,53 +22,55 @@ get_unit_code <- function(unit) { # input must have quotes to indicate strings
2222
# To do:
2323
# Warnings and checks on parameter inputs are not yet implemented.
2424
# The output dataframe is a little unwieldy and could be cleaned up.
25-
26-
27-
# It is worth figuring out how stable the URL is: when were the data last updated? How frequently are they updated? Are field codes ever changed, or just data added? Do updates entail a new URL?
25+
2826
f <- file.path(tempdir(), "irmadownload.xml")
2927
if (!file.exists(f)) {
30-
curl::curl_download("https://irmaservices.nps.gov/v2/rest/unit/", f) # access all park codes from NPS xml file
31-
# curl::curl_download(paste0("https://irmaservices.nps.gov/v2/rest/unit/",Unit, f)) #doesn't work
32-
# curl::curl_download(paste0("https://irmaservices.nps.gov/v2/rest/unit/", Unit,""), f) #works but requires removing preceding if(!file.exists(f))
33-
print("file downloaded") # check for download; remove when dev phase over
28+
# access all park codes from NPS xml file
29+
curl::curl_download("https://irmaservices.nps.gov/v2/rest/unit/", f)
3430
}
3531
result <- XML::xmlParse(file = f) # parse xml
36-
dat <- XML::xmlToDataFrame(result) # xml to dataframe
37-
dat <- dat[, c(1, 3, 5, 7, 8, 9, 11, 13)] # pare down the output some
38-
alpha <- dat %>% dplyr::filter(grepl(unit, FullName, ignore.case = TRUE)) # filter FullName for input
32+
dat <- XML::xmlToDataFrame(result)
33+
# pare down the output some
34+
dat <- dat[, c(1, 3, 5, 7, 8, 9, 11, 13)]
35+
# filter FullName for input
36+
alpha <- dat %>% dplyr::filter(grepl(unit, FullName, ignore.case = TRUE))
3937
return(alpha) # return unit code
4038
}
4139

4240

4341
#' Restricts get_unit_code to just National Parks
4442
#'
45-
#' @description \code{get_park_code} is identical to \code{get_unit_code} except output is restricted to just National Parks (as opposed to including networks, etc.).Accesses info from irmaservices.nps.gov. Search for park or park unit with any string and return all applicable national park unitCodes. Handy for use with get.dataPackage if you don't know a Park's UnitCode.
43+
#' @description `get_park_code` is identical to `get_unit_code` except the output is restricted to just National Parks (as opposed to including networks, etc.). Accesses info from irmaservices.nps.gov. Search for park or park unit with any string and return all applicable national park unitCodes.
4644
#'
4745
#' @param park is a case-insensitive string containing some part of the unit's FullName, e.g "Yellow".
4846
#'
49-
#' @return one data frame to the global environment. May contain multiple matches. Sufficient detail should be provided to choose the appropriate UnitCode for use with other NPSutils functions such as get.parkTaxonReferences (in ReferenceInfo.R). Dataframe contains UnitCode, FullName, UnitLifeCycle, Network, Region, and StateCodes.
47+
#' @return one data frame to the global environment. May contain multiple matches.
5048
#'
5149
#' @export
5250
#' @examples
5351
#' \dontrun{
5452
#' get_park_code("Yellow")
5553
#' }
56-
get_park_code <- function(park) { # case-insensitive string (in quotes) containing some part of the unit's FullName
54+
get_park_code <- function(park) {
5755
f <- file.path(tempdir(), "irmadownload.xml")
5856
if (!file.exists(f)) {
59-
curl::curl_download("https://irmaservices.nps.gov/v2/rest/unit/", f) # access all park codes from NPS xml file
57+
# access all park codes from NPS xml file
58+
curl::curl_download("https://irmaservices.nps.gov/v2/rest/unit/", f)
6059
}
6160
result <- XML::xmlParse(file = f)
62-
dat <- XML::xmlToDataFrame(result) # xml to dataframe
63-
dat <- dat %>% dplyr::filter(grepl("National Park", UnitDesignationName)) # limit search to just National Parks
64-
dat <- dat[, c(1, 3, 8, 9, 11, 13)] # cleanup the output some
65-
alpha <- dat %>% dplyr::filter(grepl(park, FullName, ignore.case = TRUE)) # filter FullName for input
61+
dat <- XML::xmlToDataFrame(result)
62+
# limit search to just National Parks
63+
dat <- dat %>% dplyr::filter(grepl("National Park", UnitDesignationName))
64+
# cleanup the output some
65+
dat <- dat[, c(1, 3, 8, 9, 11, 13)]
66+
# filter FullName for input
67+
alpha <- dat %>% dplyr::filter(grepl(park, FullName, ignore.case = TRUE))
6668
return(alpha) # return park code
6769
}
6870

6971
#' Gets information about a park Unit Code
7072
#'
71-
#' @description \code{get_unit_code_info} accesses info from irmaservices.nps.gov and allows you to search a Park Unit Code and determine which park, network, or other entity it is associated with along with ancillary information.
73+
#' @description `get_unit_code_info` accesses info from irmaservices.nps.gov and allows you to search a Park Unit Code and determine which park, network, or other entity it is associated with along with ancillary information.
7274
#'
7375
#' @param code is a case-insensitive string. It typically is 4 letters long and typically does not include numbers but may be longer, shorter, or include special characters such as "-", e.g. "SFCN".
7476
#'
@@ -79,22 +81,26 @@ get_park_code <- function(park) { # case-insensitive string (in quotes) containi
7981
#' \dontrun{
8082
#' get_unit_code_info("SFCN")
8183
#' }
82-
get_unit_code_info <- function(code) { # input must have quotes to indicate strings
84+
get_unit_code_info <- function(code) {
8385
f <- file.path(tempdir(), "irmadownload.xml")
8486
if (!file.exists(f)) {
85-
curl::curl_download(paste0("https://irmaservices.nps.gov/v2/rest/unit/", f)) # access all park codes from NPS xml file
87+
# access all park codes from NPS xml file
88+
curl::curl_download(paste0("https://irmaservices.nps.gov/v2/rest/unit/", f))
8689
}
8790
result <- XML::xmlParse(file = f)
88-
dat <- XML::xmlToDataFrame(result) # xml to dataframe
89-
dat <- dat[, c(1, 3, 8, 9, 11, 13)] # cleanup/reduce the output some
90-
alpha <- dat %>% dplyr::filter(grepl(code, UnitCode, ignore.case = TRUE)) # filter FullName for input
91-
return(alpha) # return park code
91+
dat <- XML::xmlToDataFrame(result)
92+
# cleanup/reduce the output some
93+
dat <- dat[, c(1, 3, 8, 9, 11, 13)]
94+
# filter FullName for input
95+
alpha <- dat %>% dplyr::filter(grepl(code, UnitCode, ignore.case = TRUE))
96+
# return park code
97+
return(alpha)
9298
}
9399

94100

95101
#' Search irmaservices.nps using any piece of information.
96102
#'
97-
#' @description \code{get_unit_info} accesses info from irmaservices.nps.gov and allows you to search a Park Unit based on any number or combination of parameters. Not all parameters need to be specified, but it is probably worth specifying which parameters ARE specified, e.g. get.unitInfo(LifeCycle="Inactive"). If the arguments are not specified, they will default to the order supplied in the function.
103+
#' @description `get_unit_info` accesses info from irmaservices.nps.gov and allows you to search a Park Unit based on any number or combination of parameters. Not all parameters need to be specified, but it is probably worth specifying which parameters ARE specified, e.g. get.unitInfo(LifeCycle="Inactive"). If the arguments are not specified, they will default to the order supplied in the function.
98104
#'
99105
#' @param code defaults to NULL. Is a case-insensitive string. It typically is 4 letters long and typically does not include numbers but may be longer, shorter, or include special characters such as "-".
100106
#' @param park defaults to NULL. Is a case-insensitive string. It will search for any subset of the FullName or parks or park units
@@ -121,34 +127,21 @@ get_unit_info <- function(code = NULL,
121127
net_name = NULL,
122128
region_abb = NULL,
123129
region = NULL,
124-
state = NULL) { # input must have quotes to indicate strings
130+
state = NULL) {
125131
f <- file.path(tempdir(), "irmadownload.xml")
126132
if (!file.exists(f)) {
127133
# access all park codes from NPS xml file
128134
curl::curl_download("https://irmaservices.nps.gov/v2/rest/unit/", f)
129135
}
130136
result <- XML::xmlParse(file = f)
131-
dat <- XML::xmlToDataFrame(result) # xml to dataframe
137+
dat <- XML::xmlToDataFrame(result)
132138
# check UnitCode:
133139
if (!is.null(code)) {
134-
# if(grepl("[0-9]", Code)>0){
135-
# stop("Code cannot contain numbers")
136-
# if(grepl("all", Code, ignore.case=TRUE)>1){
137-
# dat<-dat
138-
# }
139-
# else{
140140
dat <- dat %>% dplyr::filter(grepl(code, UnitCode, ignore.case = TRUE))
141-
# }
142-
# }
143141
}
144142

145143
# check UnitCycle:
146144
if (!is.null(life_cycle)) {
147-
# LifeCycle<-tolower(LifeCycle)
148-
# if( (LifeCycle == "active") + (LifeCycle == "inactive")\
149-
# (LifeCycle=="pending") < 1)
150-
# stop("LifeCycle must be \"Active\", \"Inactive\", or \"Pending\"")
151-
152145
names <- paste0("\\<", life_cycle, "\\>")
153146
dat <- dat %>% dplyr::filter(grepl(names, UnitLifecycle,
154147
ignore.case = TRUE))

‎R/load_data_package.R

-100
This file was deleted.

‎docs/404.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/LICENSE-text.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/LICENSE.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/articles/NPSutils.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/articles/index.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/authors.html

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/index.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)