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

wt_make_wide gives warning about NAs introduced by coercion #41

Closed
see24 opened this issue Jan 4, 2024 · 0 comments · Fixed by #42
Closed

wt_make_wide gives warning about NAs introduced by coercion #41

see24 opened this issue Jan 4, 2024 · 0 comments · Fixed by #42
Assignees

Comments

@see24
Copy link
Contributor

see24 commented Jan 4, 2024

The warning happens in the vignette:

library(wildRtrax)
library(dplyr)

# Start by getting everything you need
Sys.setenv(WT_USERNAME = 'guest', WT_PASSWORD = 'Apple123')
wt_auth()
#> Authentication into WildTrax successful.
my_report <- wt_download_report(project_id = 605, sensor_id = 'ARU', reports = "main", weather_cols = F) %>%
  tibble::as_tibble()

my_tidy_data <- wt_tidy_species(my_report, remove = "mammal", zerofill=F)

my_tmtt_data <- wt_replace_tmtt(data = my_tidy_data, calc = "round")

my_wide_data <- wt_make_wide(data = my_tmtt_data, sound = "all")
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `individual_count = case_when(grepl("^C", individual_count) ~
#>   NA_real_, TRUE ~ as.numeric(individual_count))`.
#> Caused by warning:
#> ! NAs introduced by coercion

Created on 2024-01-04 with reprex v2.0.2

I am pretty sure this is because when you use case_when all the right-hand sides are run even for cases where the left-hand side is not True so you get the warning even though you are dealing with the case that causes it first.

So if you change to:

mutate(individual_count = case_when(grepl("^C",  individual_count) ~ NA_character_,
                                        TRUE ~ individual_count) %>% as.numeric())

That removes the warning message.

@see24 see24 mentioned this issue Jan 4, 2024
@alexmacphail alexmacphail self-assigned this Jan 4, 2024
alexmacphail added a commit that referenced this issue Jan 9, 2024
ecknight added a commit that referenced this issue Mar 25, 2024
Fixed incompatible string type (numeric vs char) on case_when in wt_make_wide(). Should fix the bug from issue #41
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.

2 participants