Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal handling of dependent package function calls #23

Open
lmullany opened this issue Jan 2, 2025 · 1 comment
Open

internal handling of dependent package function calls #23

lmullany opened this issue Jan 2, 2025 · 1 comment

Comments

@lmullany
Copy link

lmullany commented Jan 2, 2025

There may be numerous places throughout the package where functions from dependent packages are not explicilty referenced with their dependent package. This results in limited user-ability to call functions ( Rnssp::<function>(...)) unless the entire package is loaded first (i.e. library(Rnssp)), which is sometimes not desirable.

Here is an example using the Rnssp::change_dates() function.

url <- "https://essence.syndromicsurveillance.org/nssp_essence/api/timeSeries?endDate=1May2023&startDate=1Jan2023"

Rnssp::change_dates(
  url = url,
  start_date = "2024-02-01",
  end_date = "2024-06-30"
)

Error in url %>% regmatches(., regexpr("endDate=\\d+[A-Za-z]+\\d+|end_date=\\d+[A-Za-z]+\\d+",  : 
  could not find function "%>%"

Note that in this case, the package does not correctly handle its internal usage of the magrittr pipe, requiring the user to load that package before calling the Rnssp function. Note, however, that doing so reveals another example of insufficient handling of internal dependencies, this time with the stringr package.

library(magrittr)

url <- "https://essence.syndromicsurveillance.org/nssp_essence/api/timeSeries?endDate=1May2023&startDate=1Jan2023"

Rnssp::change_dates(
  url = url,
  start_date = "2024-02-01",
  end_date = "2024-06-30"
)

Error in str_split(., "=") : could not find function "str_split"

Again, user is required to load the required package(stringr), and only then can the function be called without error:

library(magrittr)
library(stringr)

url <- "https://essence.syndromicsurveillance.org/nssp_essence/api/timeSeries?endDate=1May2023&startDate=1Jan2023"

Rnssp::change_dates(
  url = url,
  start_date = "2024-02-01",
  end_date = "2024-06-30"
)

[1] "https://essence.syndromicsurveillance.org/nssp_essence/api/timeSeries?endDate=30Jun2024&startDate=1Feb2024"

This is not the only example where internal handling of dependencies could be improved. For example:

prf = Rnssp::create_profile()
url <- "https://essence.syndromicsurveillance.org/nssp_essence"
Rnssp::get_api_response(url = url, profile = prf)

Error in url %>% httr::GET(., httr::authenticate(private$..username$value %>%  : 
  could not find function "%>%"

Finally, here is a more extended example where the user must load multiple packages. Taking the example from https://cdcgov.github.io/Rnssp/reference/alert_farrington.html:

df <- data.frame(
  date = seq(as.Date("2014-01-05"), as.Date("2022-02-05"), "weeks"),
  count = rpois(length(seq(as.Date("2014-01-05"), as.Date("2022-02-05"), "weeks")), 25)
)
df_farr_original <- Rnssp::alert_farrington(df, t = date, y = count)

Error in df %>% pull(!!enquo(t)) : could not find function "%>%"

# fix by loading magrittr, but next error is because of dependency on `dplyr`
library(magrittr)
df_farr_original <- Rnssp::alert_farrington(df, t = date, y = count)

Error in pull(., !!enquo(t)) : could not find function "pull"

# fix by loading `dplyr`, but next error is because of dependency on `tidyr`
library(dplyr)
df_farr_original <- Rnssp::alert_farrington(df, t = date, y = count)

Error in unnest(., c(data_split, anomalies)) : 
  could not find function "unnest"

# fix by loading `tidyr`, but next error is because of dependency on `purrr`
library(tidyr)
df_farr_original <- Rnssp::alert_farrington(df, t = date, y = count)

Error in `mutate()`:In argument: `anomalies = map(...)`.
Caused by error in `map()`:
! could not find function "map"

# fix by loading `purrr`
library(purrr)
df_farr_original <- Rnssp::alert_farrington(df, t = date, y = count)

Improving the internal handling of functions and operators from dependent packages could result in more seamless experience for users.

@rosericazondekon
Copy link
Collaborator

Thank you @lmullany for your contributions. We will make sure this issue is fully addressed in the upcoming version of the package. So please, stay tuned for the updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants