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

nist_ri() fails #391

Closed
stitam opened this issue Apr 24, 2023 · 5 comments
Closed

nist_ri() fails #391

stitam opened this issue Apr 24, 2023 · 5 comments
Assignees

Comments

@stitam
Copy link
Contributor

stitam commented Apr 24, 2023

While fixing another issue I realised that NIST tests fail. I think nist_ri() throws the error at line 370 in nist.R: dplyr::mutate_all(~ na_if(., "")). I see that dplyr::mutate_all() is superseded, I'm wondering if that might cause the problem? I'm going to fix this along with some other issues in a single PR (because I have to get all tests working).

If anyone knows a quick fix for this please let me know so I can fix it faster. Thanks :)

Reprex:

webchem::nist_ri("78-70-6", from = "cas", type = "alkane", polarity = "non-polar", 
    temp_prog = "custom")
#> Error in `map()`:
#> ℹ In index: 1.
#> ℹ With name: 78-70-6.
#> Caused by error in `mutate()`:
#> ℹ In argument: `RI = (structure(function (..., .x = ..1, .y = ..2, . =
#>   ..1) ...`.
#> Caused by error in `na_if()`:
#> ! Can't convert `y` <character> to match type of `x` <double>.
#> Backtrace:
#>      ▆
#>   1. ├─webchem::nist_ri(...)
#>   2. │ ├─purrr::map_dfr(ri_xmls, tidy_ritable, .id = "query") %>% ...
#>   3. │ └─purrr::map_dfr(ri_xmls, tidy_ritable, .id = "query")
#>   4. │   └─purrr::map(.x, .f, ...)
#>   5. │     └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>   6. │       ├─purrr:::with_indexed_errors(...)
#>   7. │       │ └─base::withCallingHandlers(...)
#>   8. │       ├─purrr:::call_with_cleanup(...)
#>   9. │       └─webchem (local) .f(.x[[i]], ...)
#>  10. │         └─... %>% dplyr::select("RI", "type", "phase", everything())
#>  11. ├─dplyr::mutate(., query = na_if(query, ".NA"))
#>  12. ├─dplyr::select(., "RI", "type", "phase", everything())
#>  13. ├─dplyr::mutate(...)
#>  14. ├─dplyr::mutate_all(., ~na_if(., ""))
#>  15. │ ├─dplyr::mutate(.tbl, !!!funs)
#>  16. │ └─dplyr:::mutate.data.frame(.tbl, !!!funs)
#>  17. │   └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
#>  18. │     ├─base::withCallingHandlers(...)
#>  19. │     └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
#>  20. │       └─mask$eval_all_mutate(quo)
#>  21. │         └─dplyr (local) eval()
#>  22. ├─webchem (local) `<inln_cl_>`(RI)
#>  23. │ └─rlang::eval_bare(`_quo`, base::parent.frame())
#>  24. ├─rlang (local) na_if(., "")
#>  25. ├─dplyr::na_if(., "")
#>  26. │ └─vctrs::vec_cast(x = y, to = x, x_arg = "y", to_arg = "x")
#>  27. └─vctrs (local) `<fn>`()
#>  28.   └─vctrs::vec_default_cast(...)
#>  29.     ├─base::withRestarts(...)
#>  30.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  31.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>  32.     └─vctrs::stop_incompatible_cast(...)
#>  33.       └─vctrs::stop_incompatible_type(...)
#>  34.         └─vctrs:::stop_incompatible(...)
#>  35.           └─vctrs:::stop_vctrs(...)
#>  36.             └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)

Created on 2023-04-24 with reprex v2.0.2

@stitam stitam self-assigned this Apr 24, 2023
@Aariq
Copy link
Collaborator

Aariq commented Apr 25, 2023

I can work on this if you want. I should have some time this week

@Aariq
Copy link
Collaborator

Aariq commented Apr 25, 2023

The new syntax is something like

mutate(across(everything(), ~na_if(., "")))

@ethanbass
Copy link
Contributor

ethanbass commented Apr 25, 2023

Hi,
I don't think this is because of mutate_all being deprecated, though it may be related to some other change in the latest version of dplyr since this test was passing before (when I was updating the nist_ri function a few months ago). The error is because some of the columns in the tibble are numeric and apparently they can't be coerced to character anymore to check whether they're equal to "". I haven't done any extensive testing, but it seems to work if you change line 371 to mutate_if(is.character, ~na_if(., "")) so that only character columns are mutated. I guess since mutate_if is deprecated, a better alternative could be mutate(across(where(is.character), ~na_if(., ""))) (though I think I still prefer the older syntax).

@Aariq
Copy link
Collaborator

Aariq commented Apr 25, 2023

Yeah, mutate_all() and mutate_if() are superseded, not deprecated—they're not going away, there's just a "better" way to do things now.

@stitam
Copy link
Contributor Author

stitam commented Apr 25, 2023

Many thanks @ethanbass all NIST tests pass with your suggestion! I'll fix the rest of the tests and open the PR.

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

3 participants