Skip to content

Bug: .() mis-interpreted when being used as plotmath #1912

@MichaelChirico

Description

@MichaelChirico

I just found out that sometimes .() is needed to create dynamically-labeled plots in base R:

png("~/Desktop/dterror.png")
par(mfrow = c(1, 2))
DT[ , {
  plot(1:10)
  text(2, 9, bquote(R^2 == .(summary(lm(y ~ x))$r.squared)))}]

plot(1:10)
text(2, 9, bquote(R^2 == .(summary(lm(y ~ x, data = DT))$r.squared)))
dev.off()

dterror

When used outside of [.data.table, the text is converted (as expected) to the evaluated value of the regression. But [.data.table (I imagine) is detecting this as an alias for list and substituting, leading to the unexpected result on the left.

Workaround for now is to use with(DT, {...}) instead of calling [.data.table but obviously this won't work in situations requiring other arguments of [.data.table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions