[R-pkg-devel] Rlang and Code Evalutation Within Aesthetics
Good day, I am troubled understanding why the following example doesn't work:
characteristicsList
$x `Classifier Name`
ggplot2::aes(fill = if(TRUE) NULL else !!rlang::sym(characteristicsList[["fillColour"]]))
Error in `rlang::sym()`: ! Can't convert NULL to a symbol.
rlang::last_error()
10. rlang::sym(characteristicsList[["fillColour"]]) but the following does work without error:
if(TRUE) NULL else !!rlang::sym(characteristicsList[["fillColour"]])
NULL # It is desirably avoiding the else part. The first example seems to be evaluating the else part, even though the if condition is true. The overall aim is to allow the end-user to specify a named list of appearance-modifying parameters, and for the function to create a ggplot with them, without being bamboozled if the end-user's list doesn't contain the specification for fill colour variable name or line colour variable name (like the list in the example above does not have). Thanks in advance for any suggested reading. -------------------------------------- Dario Strbenac University of Sydney Camperdown NSW 2050 Australia