DOI-USGS / DOI-USGS/streamMetabolizer
calc_light_merged throws deprecated error
- Dominant language
- Stan
- Stars
- 47
- Forks
- 25
- PR merge metrics
- No merged PRs in 30d
Description
### Brief problem description
I am trying to use the `calc_light_merged` function to model PAR based on observed PAR and the smoothed PAR produced with `calc_light`. However, the `calc_light_merged` function produces an error caused by a function that is deprecated in `dplyr` (`rename_vars`). Is there a work around for this issue?
``` r
# 1. Load libraries ----
library(tidyverse)
library(nasapower)
library(streamMetabolizer)
# 2. Download shortwave radiation from NASA POWER ----
nasa_par <- get_power(
community = 'ag',
pars = c('ALLSKY_SFC_PAR_TOT'), # All Sky Surface PAR Total (W/m^2)
temporal_api = 'hourly',
lonlat = c(-78.6, 38.7),
dates = '2010-09-19')
# 3. Some data wrangling to create the 2-column data frame needed for calc_light_merged ----
nasa_par_df <- nasa_par %>%
mutate(dateTime = make_datetime(year = YEAR,
month = MO,
day = DY,
hour = HR),
solar.time = calc_solar_time(dateTime, -78.6), # throws a warning but still works
light = convert_SW_to_PAR(ALLSKY_SFC_PAR_TOT)) %>%
select(solar.time, light) %>%
data.frame()
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `solar.time = calc_solar_time(dateTime, -78.6)`.
#> Caused by warning in `lookup_timezone()`:
#> ! Google timezone lookup now requires an API key; see http://g.co/dev/maps-no-account or provide the timezone
max_PAR_value <- max(nasa_par_df$light, na.rm = TRUE)
# 4. Apply calc_light_merged ----
light_mod <- nasa_par_df %>%
mutate(light = calc_light_merged(PAR.obs = nasa_par_df,
solar.time = solar.time,
latitude = 38.7,
longitude = -78.6,
max.PAR = max_PAR_value))
#> Error in `mutate()`:
#> ℹ In argument: `light = calc_light_merged(...)`.
#> Caused by error:
#> ! error in evaluating the argument 'object' in selecting a method for function 'deunitted': `rename_vars()` was deprecated in dplyr 0.8.4 and is now defunct.
#> ℹ Please use `tidyselect::vars_rename()` instead.
```
Created on 2024-10-22 with [reprex v2.1.1](https://reprex.tidyverse.org)
``` r
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.4.1 (2024-06-14 ucrt)
#> os Windows 11 x64 (build 22631)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.utf8
#> ctype English_United States.utf8
#> tz America/New_York
#> date 2024-10-22
#> pandoc 3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> cachem 1.1.0 2024-05-16 [1] CRAN (R 4.4.1)
#> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.1)
#> devtools 2.4.5 2022-10-11 [1] CRAN (R 4.4.1)
#> digest 0.6.36 2024-06-23 [1] CRAN (R 4.4.1)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.4.1)
#> evaluate 0.24.0 2024-06-10 [1] CRAN (R 4.4.1)
#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.1)
#> fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.1)
#> glue 1.7.0 2024-01-09 [1] CRAN (R 4.4.1)
#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1)
#> htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.4.1)
#> httpuv 1.6.15 2024-03-26 [1] CRAN (R 4.4.1)
#> knitr 1.48 2024-07-07 [1] CRAN (R 4.4.1)
#> later 1.3.2 2023-12-06 [1] CRAN (R 4.4.1)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.1)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.1)
#> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.4.1)
#> mime 0.12 2021-09-28 [1] CRAN (R 4.4.0)
#> miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.4.1)
#> pkgbuild 1.4.4 2024-03-17 [1] CRAN (R 4.4.1)
#> pkgload 1.4.0 2024-06-28 [1] CRAN (R 4.4.1)
#> profvis 0.3.8 2023-05-02 [1] CRAN (R 4.4.1)
#> promises 1.3.0 2024-04-05 [1] CRAN (R 4.4.1)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.4.1)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.1)
#> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.4.1)
#> remotes 2.5.0 2024-03-17 [1] CRAN (R 4.4.1)
#> reprex 2.1.1 2024-07-06 [1] CRAN (R 4.4.1)
#> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.1)
#> rmarkdown 2.27 2024-05-17 [1] CRAN (R 4.4.1)
#> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.4.1)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.1)
#> shiny 1.8.1.1 2024-04-02 [1] CRAN (R 4.4.1)
#> stringi 1.8.4 2024-05-06 [1] CRAN (R 4.4.0)
#> stringr 1.5.1 2023-11-14 [1] CRAN (R 4.4.1)
#> urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.4.1)
#> usethis 2.2.3 2024-02-19 [1] CRAN (R 4.4.1)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.1)
#> withr 3.0.0 2024-01-16 [1] CRAN (R 4.4.1)
#> xfun 0.45 2024-06-16 [1] CRAN (R 4.4.1)
#> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.4.1)
#> yaml 2.3.9 2024-07-05 [1] CRAN (R 4.4.1)
#>
#> [1] C:/Users/stassone/AppData/Local/Programs/R/R-4.4.1/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
```
Created on 2024-10-22 with [reprex v2.1.1](https://reprex.tidyverse.org)
Contributor guide
Research direction
Start by tracing the calc_light_merged entry point and the reported rename_vars call, then compare how calc_light handles the same inputs. The payload names no source or test files, so locate the function and any existing light-calculation tests first. Done means calc_light_merged runs with the supplied PAR data without the deprecated-function error and preserves its expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100