leifeld / dna

Discourse Network Analyzer (DNA)
130 stars 41 forks source link

Updates #286

Closed Krgaric closed 1 year ago

leifeld commented 1 year ago

Let's try to wrap this PR up soon. Did you want to add anything else regarding aes_string or backbone plotting? Can you make the requested changes? Thanks.

Krgaric commented 1 year ago

All previous comments resolved. There is still an issue with autoplot function in dna_backbone. Here is the error log:

Error inggplot2::geom_line(): ! Problem while computing aesthetics. ℹ Error occurred in the 1st layer. Caused by error: ! Can't subset.dataoutside of a data mask context. Runrlang::last_trace()` to see where the error occurred.

rlang::last_trace() <error/rlang_error> Error in ggplot2::geom_line(): ! Problem while computing aesthetics. ℹ Error occurred in the 1st layer. Caused by error: ! Can't subset .data outside of a data mask context.

Backtrace: ▆

  1. ├─base (local) <fn>(x)
  2. ├─ggplot2:::print.ggplot(x)
  3. │ ├─ggplot2::ggplot_build(x)
  4. │ └─ggplot2:::ggplot_build.ggplot(x)
  5. │ └─ggplot2:::by_layer(...)
  6. │ ├─rlang::try_fetch(...)
  7. │ │ ├─base::tryCatch(...)
  8. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  9. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
  10. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
  11. │ │ └─base::withCallingHandlers(...)
  12. │ └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
  13. │ └─l$compute_aesthetics(d, plot)
  14. │ └─ggplot2 (local) compute_aesthetics(..., self = self)
  15. │ └─ggplot2:::scales_add_defaults(...)
  16. │ └─base::lapply(aesthetics[new_aesthetics], eval_tidy, data = data)
  17. │ └─rlang (local) FUN(X[[i]], ...)
  18. ├─rlang::.data[["iteration"]]
  19. └─rlang:::[[.rlang_fake_data_pronoun(rlang::.data, "iteration")
  20. └─rlang:::stop_fake_data_subset(call)
  21. └─rlang::abort(...)

The error occurs somewhere between lines 2851 and 2956. I checked all the geom_lines where "iteration" appears but cannot find anything odd.

leifeld commented 1 year ago

Thanks. I hope you can figure it out. Let me tag @TimHenrichsen . Tim, can you help? Kristijan fixed the aes_string problem, but there is some issue with the backbone autoplot code.

TimHenrichsen commented 1 year ago

Hi Kristijan and thanks for all the work! I could reproduce your issue and noticed that I also couldn't compute other autoplot functions. I checked the .data help file which says the following:

The .data pronoun is automatically created for you by data-masking functions using the tidy eval framework. You don't need to import rlang::.data or use library(rlang) to work with this pronoun.

However, the .data object exported from rlang is useful to import in your package namespace to avoid a ⁠R CMD check⁠ note when referring to objects from the data mask. R does not have any way of knowing about the presence or absence of .data in a particular scope so you need to import it explicitly or equivalently declare it with utils::globalVariables(".data").

Note that rlang::.data is a "fake" pronoun. Do not refer to rlang::.data with the ⁠rlang::⁠ qualifier in data masking code. Use the unqualified .data symbol that is automatically put in scope by data-masking functions.

Could you test if the autoplot functions work, when you remove rlang:: before every .data command?

Krgaric commented 1 year ago

Hi Kristijan and thanks for all the work! I could reproduce your issue and noticed that I also couldn't compute other autoplot functions. I checked the .data help file which says the following:

The .data pronoun is automatically created for you by data-masking functions using the tidy eval framework. You don't need to import rlang::.data or use library(rlang) to work with this pronoun.

However, the .data object exported from rlang is useful to import in your package namespace to avoid a ⁠R CMD check⁠ note when referring to objects from the data mask. R does not have any way of knowing about the presence or absence of .data in a particular scope so you need to import it explicitly or equivalently declare it with utils::globalVariables(".data").

Note that rlang::.data is a "fake" pronoun. Do not refer to rlang::.data with the ⁠rlang::⁠ qualifier in data masking code. Use the unqualified .data symbol that is automatically put in scope by data-masking functions.

Could you test if the autoplot functions work, when you remove rlang:: before every .data command?

Dear @TimHenrichsen, thank you, it works now. It plots as supposed, but there are some warning messages that should be checked out: Warning messages: 1: Removed 499 rows containing missing values (geom_line()). 2: Removed 998 rows containing missing values (geom_line()). 3: Removed 499 rows containing missing values (geom_line()).

use the gridExtra package to arrange the diagnostics in a single plot

library("gridExtra") grid.arrange(p[[1]], p[[2]], p[[3]], p[[4]]) Don't know how to automatically pick scale for object of type . Defaulting to continuous. Don't know how to automatically pick scale for object of type . Defaulting to continuous. Warning messages: 1: Removed 499 rows containing missing values (geom_line()). 2: Removed 998 rows containing missing values (geom_line()). 3: Removed 499 rows containing missing values (geom_line()).

This was ran on the sample example. Is something like that expected?

Thank you for the help so far!

leifeld commented 1 year ago

The checks below say that you need to put rlang in the DESCRIPTION file under Imports.

Krgaric commented 1 year ago

The checks below say that you need to put rlang in the DESCRIPTION file under Imports.

Resolved.

leifeld commented 1 year ago

You forgot the comma in the line before. See new errors in the check log below.