StoXProject / RstoxFDA

Fisheries Dependent Analysis with Rstox
https://stoxproject.github.io/RstoxFDA
GNU Lesser General Public License v3.0
0 stars 1 forks source link

get rid of aes_string #87

Closed edvinf closed 10 months ago

edvinf commented 1 year ago

ggplot2::aesstring and ggplot2::aes is flagged as deprecated. RstoxFDA uses this a lot to avoid global-variable warnings in code checks. We should replace this with tidy evaluation idioms.

Basically we are using ggplot2::aes_string in many places to avoid global variable warnings, and to allow parameterisation of the variable used in plotting. ggplot want us to use ggplot2::aes. We can change ggplot2::aes_string(x="variable") to ggplot2::aes_string(x=variable). In both cases variable refer to the same column of a data.table passed to ggplot, but in the latter case it looks to standard r as an unbound variable, which produces a warning during checks. We need to decide on how to get rid of R CMD check notes about global variables, there are plenty of ugly hacks around, but I'll try to list the least ugly ones below:

One popular suggestion is to use the .data$var construct (https://community.rstudio.com/t/how-to-solve-no-visible-binding-for-global-variable-note/28887/4)

In addition we need a new solution for parameterized variables passed to ggplot. E.g.: var="variable" ggplot2::aes_string(var) produces the same effect as the examples above, but var may be set at runtime to something else for making configurable plots.

This also seems to be handle by the .data pronoun approach. See the section 'lifecycle' at https://ggplot2.tidyverse.org/reference/aes_.html

edvinf commented 1 year ago

See also https://jira.imr.no/browse/STOX-675