[R-pkg-devel] Rlang and Code Evalutation Within Aesthetics
Jeff Newmiller
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Sat Apr 30 16:53:19 CEST 2022
Things like sensible legends are also impeded by using complex expressions in aesthetics mappings, so call it a workaround if you like but creating the data frame the way it should be _before_ giving it to ggplot has always been recommended.
On April 30, 2022 5:09:51 AM PDT, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>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
>
>______________________________________________
>R-package-devel using r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-package-devel
--
Sent from my phone. Please excuse my brevity.
More information about the R-package-devel
mailing list