WinVector / wrapr

Wrap R for Sweet R Code
https://winvector.github.io/wrapr/
Other
136 stars 11 forks source link

Unexpected Behavior #13

Closed tpWalker888 closed 3 years ago

tpWalker888 commented 3 years ago

John, long time user of your products but the updated qc is not acting like I believe it should.

t1 <- c('ABC-PB','DEF-PB') t2 <- qc(ABC-PB,DEF-PB) identical(t1,t2)

t2 is appearing as ('ABC - PB','DEF - PB') - notice the spaces around the "-" thanks for all your efforts!

JohnMount commented 3 years ago

tpWalker888,

Thanks for your comment, and sorry if that is causing you trouble. That is a behavior that is due to how R passes in function arguments. Underbar (_) won't introduce spaces, as it is a valid identifier character, and minus (-) will as the R convention is spaces around operators.

Roughly, spacing is not detectable in the arguments to an R function. The called function doesn't appear to be able to determine if one wrote f(a-b) or f(a - b). This is what is causing what you observed with wrapr, which is using the default formatting conventions of R, which inserts the spaces.

For situations where one wants space removal/splitting, I have just introduced a new function in wrapr 2.0.7, which works as follows bc('ABC-PB,DEF-PB') is identical to c("ABC-PB", "DEF-PB"). To get this to work we need the entire argument in quotes, as R functions are passed their arguments already parsed (not as raw text) but not evaluated.

So, thank you for the report- but this isn't something that one can easily change the behavior of in pure R.

tpWalker888 commented 3 years ago

John, That's an excellent solution thanks. Gerry

On February 4, 2021 9:36:24 AM John Mount notifications@github.com wrote:

tpWalker888, Thanks for your comment, and sorry if that is causing you trouble. That is a behavior that is due to how R passes in function arguments. Roughly, spacing is not detectable in the arguments to an R function. The called function doesn't appear to be able to determine if one write f(a-b) or f(a - b). This is what is causing what you observed with wrapr, which is using the default formatting conventions of R, which inserts the spaces. For situations where one wants space removal/splitting, I have just introduced a new function in wrapr 2.0.7, which works as follows bc('ABC-PB,DEF-PB') is identical to c("ABC-PB", "DEF-PB"). To get this to work we need the entire argument in quotes, as R functions are passed their arguments already parsed (not as raw text) but not evaluated. So, thank you for the report- but this isn't something that one can easily change the behavior of in pure R. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.