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

to_lower() in check_names() causes error if upper cases used. #41

Closed
dhope opened this issue Jul 3, 2024 · 1 comment · Fixed by #43
Closed

to_lower() in check_names() causes error if upper cases used. #41

dhope opened this issue Jul 3, 2024 · 1 comment · Fixed by #43

Comments

@dhope
Copy link
Collaborator

dhope commented Jul 3, 2024

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

library(ARUtools)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(purrr)
#> 
#> Attaching package: 'purrr'
#> The following object is masked from 'package:base':
#> 
#>     %||%
library(tidyr)
library(glue)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
s <- clean_site_index(example_sites_clean,
                      name_date = c("date_time_start", "date_time_end")
)
m <- clean_metadata(project_files = example_files) |>
  add_sites(s) |>
  calc_sun() |>
  mutate(
    time_period = if_else(hour(date_time) < 6, "early", "late"),
    year = year(date)
  )
#> Extracting ARU info...
#> Extracting Dates and Times...
#> Joining by columns `date_time_start` and `date_time_end`
p <- list(
  "early" = sim_selection_weights(min_range = c(-70, 240)),
  "late" = sim_selection_weights(min_range = c(100, 300), min_mean = 200)
)

w <- m |>
  nest(data = c(-time_period, -year)) |>
  mutate(
    params = p,
    sel = map2(data, params, calc_selection_weights)
  ) |>
  unnest(sel) |>
  select(-"data", -"params") |>
  mutate(Selection_group = glue("{site_id}_{year}_{time_period}"))
n <- w |>
  summarize(n_recordings = n(), .by = c("Selection_group", "time_period")) |>
  mutate(
    n = if_else(time_period == "early", 5, 2),
    n_os = if_else(time_period == "early", floor(n * 1 / 3), floor(n * 1 / 4)),
    n_os = pmax(0, pmin(n_recordings - n, round(n / 3))),
    n = pmin(n, n_recordings)
  )

g <- sample_recordings(w, n,
                       col_site_id = Selection_group,
                       col_sel_weights = psel_normalized
)
#> Error in `sample_recordings()`:
#> ! Problems with data `n`:
#> • Column 'Selection_group' does not exist

Created on 2024-07-03 with reprex v2.1.0.9000

Expected behavior
Having upper case column names shouldn't cause the function to fail and if that is wanted, it should at least be clear about why it is throwing an error.

@dhope dhope mentioned this issue Jul 3, 2024
11 tasks
dhope added a commit that referenced this issue Jul 4, 2024
@dhope
Copy link
Collaborator Author

dhope commented Jul 4, 2024

Fixed for now with 57ac7a7, however still have some concerns about use of tolower() in check_names()

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

Successfully merging a pull request may close this issue.

1 participant