From 50b5918e4ffbf7e91615d9cc033a357c96923e6e Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Sat, 18 May 2024 10:25:24 +0800 Subject: [PATCH] Closes #85 (#86) --- DESCRIPTION | 2 +- NEWS.md | 4 +++ R/query_parameters.R | 29 ++++++++---------- codemeta.json | 8 ++--- man/query_parameters.Rd | 9 ++++-- vignettes/{precompile.R => !precompile.R} | 0 vignettes/nasapower.Rmd | 37 ++++++++++++----------- 7 files changed, 47 insertions(+), 42 deletions(-) rename vignettes/{precompile.R => !precompile.R} (100%) diff --git a/DESCRIPTION b/DESCRIPTION index d3de108b..968a27cb 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: nasapower Title: NASA POWER API Client -Version: 4.2.0 +Version: 4.2.1 Authors@R: c( person("Adam H.", "Sparks", , "adamhsparks@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-0061-8359")), diff --git a/NEWS.md b/NEWS.md index 87a2090b..747197e3 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# nasapower 4.2.1 + +* Fixes [Issue](https://github.com/ropensci/nasapower/issues/85) where querying all parameters failed. + # nasapower 4.2.0 ## Minor Changes diff --git a/R/query_parameters.R b/R/query_parameters.R index 28ac4a69..9ad6b347 100644 --- a/R/query_parameters.R +++ b/R/query_parameters.R @@ -7,7 +7,7 @@ #' #' @param community An optional character vector providing community name: #' \dQuote{ag}, \dQuote{sb} or \dQuote{re}. -#' @param pars A required character string of a single solar, meteorological or +#' @param pars An optional character string of a single solar, meteorological or #' climatology parameter to query. #' @param temporal_api An optional character vector indicating the temporal #' \acronym{API} end-point for data being queried, supported values are @@ -51,14 +51,11 @@ #' @export query_parameters <- function(community = NULL, - pars, + pars = NULL, temporal_api = NULL, metadata = FALSE) { community_vals <- c("AG", "RE", "SB") - temporal_api_vals <- c("DAILY", - "MONTHLY", - "HOURLY", - "CLIMATOLOGY") + temporal_api_vals <- c("DAILY", "MONTHLY", "HOURLY", "CLIMATOLOGY") # if the args for `community` and `temporal_api` are not empty, check and # then reset `community_vals` and `temporal_api_vals` for use later @@ -82,12 +79,13 @@ query_parameters <- function(community = NULL, temporal_api_vals <- temporal_api } - pars <- toupper(pars) - pars <- - .check_pars(pars = pars, - community = community_vals, - temporal_api = temporal_api_vals) - + if (!is.null(pars)) { + pars <- toupper(pars) + pars <- + .check_pars(pars = pars, + community = community_vals, + temporal_api = temporal_api_vals) + } power_url <- "https://power.larc.nasa.gov/api/system/manager/parameters" @@ -96,11 +94,9 @@ query_parameters <- function(community = NULL, "%s/%s?user=nasapower4r", power_url, pars ))) } else { - if (!.is_boolean(metadata)) { cli::cli_abort( - c(x = "{.arg metadata} should be a Boolean value.", - i = "{Please provide either {.var TRUE} or {.var FALSE}.") + c(x = "{.arg metadata} should be a Boolean value.", i = "{Please provide either {.var TRUE} or {.var FALSE}.") ) } @@ -114,8 +110,7 @@ query_parameters <- function(community = NULL, ) query_list <- query_list[lengths(query_list) != 0] - response <- .send_query(.query_list = query_list, - .url = power_url) + response <- .send_query(.query_list = query_list, .url = power_url) return(jsonlite::fromJSON(response$parse(encoding = "UTF8"))) } diff --git a/codemeta.json b/codemeta.json index 57374d46..520434c4 100644 --- a/codemeta.json +++ b/codemeta.json @@ -7,7 +7,7 @@ "codeRepository": "https://github.com/ropensci/nasapower", "issueTracker": "https://github.com/ropensci/nasapower/issues", "license": "https://spdx.org/licenses/MIT", - "version": "4.2.0", + "version": "4.2.1", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", @@ -251,7 +251,7 @@ "applicationCategory": "Tools", "isPartOf": "https://ropensci.org", "keywords": ["NASA", "meteorological-data", "weather", "global", "weather-data", "meteorology", "NASA-POWER", "agroclimatology", "earth-science", "data-access", "climate-data", "r", "nasa-power", "nasa", "agroclimatology-data", "weather-variables", "rstats", "r-package"], - "fileSize": "496.327KB", + "fileSize": "496.399KB", "citation": [ { "@type": "SoftwareSourceCode", @@ -265,7 +265,7 @@ "name": "{nasapower}: NASA-POWER Data from R", "identifier": "10.5281/zenodo.1040727", "url": "https://CRAN.R-project.org/package=nasapower", - "description": "R package version 4.2.0", + "description": "R package version 4.2.1", "@id": "https://doi.org/10.5281/zenodo.1040727", "sameAs": "https://doi.org/10.5281/zenodo.1040727" }, @@ -299,7 +299,7 @@ "relatedLink": ["https://docs.ropensci.org/nasapower/", "https://CRAN.R-project.org/package=nasapower"], "releaseNotes": "https://github.com/ropensci/nasapower/blob/master/NEWS.md", "readme": "https://github.com/ropensci/nasapower/blob/main/README.md", - "contIntegration": ["https://github.com/ropensci/nasapower/actions", "https://app.codecov.io/gh/ropensci/nasapower"], + "contIntegration": ["https://github.com/ropensci/nasapower/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/ropensci/nasapower"], "developmentStatus": "https://www.repostatus.org/#active", "review": { "@type": "Review", diff --git a/man/query_parameters.Rd b/man/query_parameters.Rd index d4e41cde..4d9edcba 100644 --- a/man/query_parameters.Rd +++ b/man/query_parameters.Rd @@ -4,13 +4,18 @@ \alias{query_parameters} \title{Query the POWER API for Detailed Information on Available Parameters} \usage{ -query_parameters(community = NULL, pars, temporal_api = NULL, metadata = FALSE) +query_parameters( + community = NULL, + pars = NULL, + temporal_api = NULL, + metadata = FALSE +) } \arguments{ \item{community}{An optional character vector providing community name: \dQuote{ag}, \dQuote{sb} or \dQuote{re}.} -\item{pars}{A required character string of a single solar, meteorological or +\item{pars}{An optional character string of a single solar, meteorological or climatology parameter to query.} \item{temporal_api}{An optional character vector indicating the temporal diff --git a/vignettes/precompile.R b/vignettes/!precompile.R similarity index 100% rename from vignettes/precompile.R rename to vignettes/!precompile.R diff --git a/vignettes/nasapower.Rmd b/vignettes/nasapower.Rmd index 60440c63..3ee9a167 100644 --- a/vignettes/nasapower.Rmd +++ b/vignettes/nasapower.Rmd @@ -26,7 +26,7 @@ The `get_power()` function has eight possible arguments and returns a data frame Fetch daily "AG" community temperature, relative humidity and precipitation for January 1985 for Kingsthorpe, Queensland, Australia. -```r +``` r library("nasapower") daily_single_ag <- get_power( community = "ag", @@ -70,7 +70,7 @@ daily_single_ag Fetch daily "ag" community relative humidity and temperature for south east Queensland region. -```r +``` r daily_region_ag <- get_power( community = "ag", lonlat = c(150.5, -28.5 , 153.5, -25.5), @@ -112,7 +112,7 @@ daily_region_ag Fetch interannual solar cooking parameters for south east Queensland region. -```r +``` r interannual_re <- get_power( community = "re", lonlat = c(150.5, -28.5 , 153.5, -25.5), @@ -135,19 +135,20 @@ interannual_re #> CLRSKY_SFC_SW_DWN CERES SYN1deg Clear Sky Surface Shortwave Downward Irradiance (kW-hr/m^2/day) #> #> # A tibble: 144 × 17 -#> PARAMETER YEAR LAT LON JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANN -#> -#> 1 ALLSKY_SFC_SW_DWN 1984 -25.8 151. 6.01 6.49 5.79 4.67 4.12 3.77 2.46 4.87 6.11 5.5 7.97 7.03 5.39 -#> 2 ALLSKY_SFC_SW_DWN 1984 -25.8 151. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6 6.76 5.19 -#> 3 ALLSKY_SFC_SW_DWN 1984 -25.8 152. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6 6.76 5.19 -#> 4 ALLSKY_SFC_SW_DWN 1984 -25.8 152. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23 6.68 5.06 -#> 5 ALLSKY_SFC_SW_DWN 1984 -25.8 153. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23 6.68 5.06 -#> 6 ALLSKY_SFC_SW_DWN 1984 -25.8 153. 6.23 6.05 5.88 4.26 3.81 3.3 2.96 4.73 5.66 5.25 7.6 7.06 5.23 -#> 7 ALLSKY_SFC_SW_DWN 1984 -26.2 151. 5.97 6.65 6 4.66 4.02 3.72 2.28 4.86 6.08 5.74 7.74 6.97 5.38 -#> 8 ALLSKY_SFC_SW_DWN 1984 -26.2 151. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46 6.89 5.24 -#> 9 ALLSKY_SFC_SW_DWN 1984 -26.2 152. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46 6.89 5.24 -#> 10 ALLSKY_SFC_SW_DWN 1984 -26.2 152. 5.75 5.96 5.37 4.13 3.8 3.44 2.38 4.81 5.75 4.99 6.94 6.56 4.98 +#> PARAMETER YEAR LAT LON JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV +#> +#> 1 ALLSKY_SFC_SW… 1984 -25.8 151. 6.01 6.49 5.79 4.67 4.12 3.77 2.46 4.87 6.11 5.5 7.97 +#> 2 ALLSKY_SFC_SW… 1984 -25.8 151. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6 +#> 3 ALLSKY_SFC_SW… 1984 -25.8 152. 5.92 5.97 5.64 4.37 4.01 3.61 2.6 4.8 5.84 5.24 7.6 +#> 4 ALLSKY_SFC_SW… 1984 -25.8 152. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23 +#> 5 ALLSKY_SFC_SW… 1984 -25.8 153. 5.96 5.85 5.56 4.26 3.92 3.52 2.66 4.59 5.58 4.94 7.23 +#> 6 ALLSKY_SFC_SW… 1984 -25.8 153. 6.23 6.05 5.88 4.26 3.81 3.3 2.96 4.73 5.66 5.25 7.6 +#> 7 ALLSKY_SFC_SW… 1984 -26.2 151. 5.97 6.65 6 4.66 4.02 3.72 2.28 4.86 6.08 5.74 7.74 +#> 8 ALLSKY_SFC_SW… 1984 -26.2 151. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46 +#> 9 ALLSKY_SFC_SW… 1984 -26.2 152. 6 6.38 5.71 4.38 4.01 3.66 2.17 4.88 6.01 5.43 7.46 +#> 10 ALLSKY_SFC_SW… 1984 -26.2 152. 5.75 5.96 5.37 4.13 3.8 3.44 2.38 4.81 5.75 4.99 6.94 #> # ℹ 134 more rows +#> # ℹ 2 more variables: DEC , ANN ``` ### Example fetching climatology data @@ -158,7 +159,7 @@ Change the `temporal_api` value to "climatology" to get these data. Fetch "ag" climatology for temperature and relative humidity for Kingsthorpe, Queensland, Australia. -```r +``` r climatology_ag <- get_power( community = "ag", pars = c("T2M", "RH2M"), @@ -195,7 +196,7 @@ This can be used to find available parameter names and definitions for each comm Fetch the complete available information for the temperature at 2 metres above the Earth's surface, T2M. -```r +``` r query_parameters(pars = "T2M") #> $T2M #> $T2M$temporal @@ -263,7 +264,7 @@ query_parameters(pars = "T2M") Fetch complete temporal and community specific attribute information for "T2M" in the "ag" community for the "hourly" temporal API. -```r +``` r query_parameters(pars = "T2M", community = "ag", temporal_api = "hourly")