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

downloadDMRs creates a tibble that doesn't unnest easily #42

Open
mps9506 opened this issue Jul 11, 2019 · 0 comments
Open

downloadDMRs creates a tibble that doesn't unnest easily #42

mps9506 opened this issue Jul 11, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@mps9506
Copy link
Owner

mps9506 commented Jul 11, 2019

The nested tibble from downloadDMRs() relies on the user mapping column types to unnest the dmr column:

library(dplyr)
library(echor)

df <- tibble::tibble(permit = c("TX0021474", "TX0023051", "TXG130053"))
df <- downloadDMRs(df, idColumn = permit, start_date = "01/01/2010",
                   end_date = "12/30/2017", parameter_code = "50050")

df %>% tidyr::unnest(dmr)

Results in the following message:

Error: Column `monitoring_location_code` can't be converted from character to numeric

I have to follow up with the following to unnest the data:

df %>%
  mutate(n = purrr::map(dmr, ~nrow(.))) %>%
  mutate(dmr = purrr::map(dmr, ~mutate(.x,
                                version_nmbr = as.character(version_nmbr),
                                monitoring_location_code = as.character(monitoring_location_code),
                                exceedence_pct = as.character(exceedence_pct),
                                rnc_detection_date = as.character(rnc_detection_date),
                                rnc_resolution_code = as.character(rnc_resolution_code),
                                rnc_resolution_date = as.character(rnc_resolution_date),
                                days_late = as.character(days_late),
                                nodi_code = as.character(nodi_code),
                                dmr_value_nmbr = as.numeric(dmr_value_nmbr),
                                dmr_value_standard_units = as.numeric(dmr_value_standard_units),
                                limit_value_nmbr = as.numeric(limit_value_nmbr),
                                limit_value_standard_units = as.numeric(limit_value_standard_units)))) %>%
  tidyr::unnest(dmr)

The user should not have to figure this out, but if the above code is hardcoded, it will be prone to breaking if the columns returned by the API ever change.

@mps9506 mps9506 added the enhancement New feature or request label Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant