[R-pkg-devel] Rlang and Code Evalutation Within Aesthetics

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sat Apr 30 14:09:51 CEST 2022


On 30/04/2022 8:00 a.m., Dario Strbenac wrote:
> 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.

I'm pretty sure this isn't the right place to ask about ggplot2, but 
that looks like a bug to me.

Duncan Murdoch



More information about the R-package-devel mailing list