iqis / Q7

Freestyle Object Oriented Programming in R
GNU General Public License v3.0
5 stars 1 forks source link

define type by another function #19

Closed elong0527 closed 2 years ago

elong0527 commented 3 years ago

May I ask why this definition is OK

size <- Q7::type( function(size){ }, s3 = "ggsd.size")
x <- size(1)

But below definition result in error.

type_size <- function(size){ }
size <- Q7::type(type_size, s3 = "ggsd.size")
x <- size(1)

@nanxstats

nanxstats commented 3 years ago

I guess it is related to how the first argument x is processed in type(): https://github.com/iqis/Q7/blob/master/R/core.R#L21.

deparse(substitute()) uses non-standard evaluation to capture the expression or function as character strings, so that you cannot use a variable there but have to write the actual content. This is the same behavior as in library().

adv-r suggested providing an escape hatch or standard evaluation version but I'm not sure if it's worth it here.

iqis commented 2 years ago

Thanks @nanxstats. You are spot-on. This will be fixed.