grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
204 stars 7 forks source link

`as.data.frame()` first for data? #132

Closed eitsupi closed 4 months ago

eitsupi commented 4 months ago

I don't know if this can be called a bug, but I seem to get a strange error when I pass arrow::Table to the data argument.

tinyplot::tinyplot(Sepal.Length ~ Petal.Length | Species, data = arrow::as_arrow_table(iris))
#> Error in list(Sepal.Length, Petal.Length, Species): could not find function "list"

Created on 2024-02-27 with reprex v2.0.2

Perhaps this is related to the fact that columns can be accessed by $ in the environment of the arrow::Table object?

In any case, I thought it might work better with objects like data frames by having as.data.frame() run first in the tinyplot function.

grantmcdermott commented 4 months ago

Thanks for the suggestion.

Perhaps we should be doing a check for inherits(data, c("data.frame", "list")) internally first anyway. Then we could attempt an as.data.frame coercion if this condition is not met.

OTOH are we going to run into scoping issues because of confusion between the data argument and utils::data() function?

zeileis commented 4 months ago

I wouldn't touch the data directly but rely on the standard non-standard evaluation via model.frame(). This is what base plot() does but also lm() and friends:

plot(Sepal.Length ~ Petal.Length, data = arrow::as_arrow_table(iris))
## Error in list(Sepal.Length, Petal.Length) : 
##   could not find function "list"
lm(Sepal.Length ~ Petal.Length, data = arrow::as_arrow_table(iris))
## Error in list(Sepal.Length, Petal.Length) : 
##   could not find function "list"

So this seems to be something to reconcile more generally, not necessarily within tinyplot. Also, I'm not sure whether calling as.data.frame() first might have any side effects for some of the objects that are currently supported.

eitsupi commented 4 months ago

Thanks for your prompt reply, perhaps this is a base function issue (not working properly for R6 classes?) as it works fine with polars::as_polars_df or arrow:::as_adq.

In any case, I don't think this is the issue here, so I'll close it.