CC-HIC / inspectEHR

A data wrangling, cleaning and reporting tool for CC-HIC
https://cc-hic.github.io/inspectEHR/
6 stars 2 forks source link

Issue in extract_timevarying following upgrade to rlang 0.4.0 #4

Closed DocEd closed 5 years ago

DocEd commented 5 years ago

Problem occurs when trying to run extract_timevarying. Error message as below:

As below:

Error: Cannot embed a data frame in a SQL query.

If you are seeing this error in code that used to work, the most likely cause is a change dbplyr 1.4.0. Previously df$x or df[[y]] implied that df was a local variable, but now you must make that explict with !! or local(), e.g., !!df$x or local(df[["y"])) Callrlang::last_error()` to see a backtrace

Struggling to find the root of the problem as this all works when I take things out of the function. So presumably this is an environment/scoping issue.

DocEd commented 5 years ago
  1. ├─inspectEHR::extract_timevarying(ctn, "NIHR_HIC_ICU_0108")
  2. │ └─%>%(...) R/extract_timevarying.R:55:2
  3. │ ├─base::withVisible(eval(quote(_fseq(_lhs)), env, env))
  4. │ └─base::eval(quote(_fseq(_lhs)), env, env)
  5. │ └─base::eval(quote(_fseq(_lhs)), env, env)
  6. │ └─inspectEHR:::_fseq(_lhs)
  7. │ └─magrittr::freduce(value, _function_list)
  8. │ └─function_list[i]
  9. │ └─purrr::map(...)
    1. │ └─inspectEHR:::.f(.x[[i]], ...)
    2. │ └─%>%(...) R/extract_timevarying.R:63:6
    3. │ ├─base::withVisible(eval(quote(_fseq(_lhs)), env, env))
    4. │ └─base::eval(quote(_fseq(_lhs)), env, env)
    5. │ └─base::eval(quote(_fseq(_lhs)), env, env)
    6. │ └─inspectEHR:::_fseq(_lhs)
    7. │ └─magrittr::freduce(value, _function_list)
    8. │ ├─base::withVisible(function_list[k])
    9. │ └─function_list[k]
    10. │ ├─dplyr::collect(.)
    11. │ └─dbplyr:::collect.tbl_sql(.)
    12. │ ├─dbplyr::db_sql_render(x$src$con, x)
    13. │ └─dbplyr:::db_sql_render.DBIConnection(x$src$con, x)
    14. │ ├─dbplyr::sql_render(sql, con = con, ...)
    15. │ └─dbplyr:::sql_render.tbl_lazy(sql, con = con, ...)
    16. │ ├─dbplyr::sql_render(query$ops, con = con, ..., bare_identifier_ok = bare_identifier_ok)
    17. │ └─dbplyr:::sql_render.op(query$ops, con = con, ..., bare_identifier_ok = bare_identifier_ok)
    18. │ ├─dbplyr::sql_build(query, con = con, ...)
    19. │ └─dbplyr:::sql_build.op_filter(query, con = con, ...)
    20. │ └─dbplyr::translatesql(op$dots, con, context = list(clause = "WHERE"))
    21. │ └─base::lapply(...)
    22. │ └─dbplyr:::FUN(X[[i]], ...)
    23. │ ├─dbplyr::escape(eval_tidy(x, mask), con = con)
    24. │ └─rlang::eval_tidy(x, mask)
    25. ├─%in%(...)
    26. │ └─dbplyr::is.sql(table)
    27. └─...$NULL
    28. └─dbplyr::build_sql(x, sql(f), y)
    29. └─purrr::map_chr(enexprs(...), escape_expr, con = con)
    30. └─dbplyr:::.f(.x[[i]], ...)
    31. ├─dbplyr::escape(val, con = con)
    32. └─dbplyr:::escape.data.frame(val, con = con)
DocEd commented 5 years ago

Taceback stack above. I've added a file at data-raw/working.R with a demo file to try and reproduce the error. @klapaukh would you mind taking a look and seeing if you could point out an obvious flaw?

DocEd commented 5 years ago

Fixed. We needed a !! when a data frame was being passed into map