Compatability with R's with() function

Discuss the jamovi platform, possible improvements, etc.
Post Reply
User avatar
BobMuenchen
Posts: 16
Joined: Thu Jan 18, 2018 6:24 pm
Location: Knoxville
Contact:

Compatability with R's with() function

Post by BobMuenchen »

When using jmv code, it would be helpful if the with() function could pass in data. Currently it generates an error:

> with(mydata100,
+ contTables(rows = "workshop",
+ cols = "gender",
+ pcRow = TRUE)
+ )
Error in super$initialize(package = "jmv", name = "contTables", version = c(1, :
argument "data" is missing, with no default
> contTables(data = mydata100,
+ rows = "workshop",
+ cols = "gender",
+ pcRow = TRUE)
User avatar
jonathon
Posts: 2609
Joined: Fri Jan 27, 2017 10:04 am

Re: Compatability with R's with() function

Post by jonathon »

righto, i'll take a look at the `with()` function.

(although i am having difficulty getting jmvcore updates to CRAN at the moment. it works everywhere except their debian environment, but they won't tell me why, and i can't reproduce on any of my VMs :/)
User avatar
BobMuenchen
Posts: 16
Joined: Thu Jan 18, 2018 6:24 pm
Location: Knoxville
Contact:

Re: Compatability with R's with() function

Post by BobMuenchen »

Thanks!
User avatar
jonathon
Posts: 2609
Joined: Fri Jan 27, 2017 10:04 am

Re: Compatability with R's with() function

Post by jonathon »

hi bob,

do you understand how `with()` works?
with is a generic function that evaluates expr in a local environment constructed from data
so i would expect the following to create a new environment containing the variables 'len', 'dose' and 'supp', and ls() to show as much:

Code: Select all

data('ToothGrowth')

callback <- function(...) {
    print(ls())
}

with(ToothGrowth, callback())
but all that's printed is an empty character() vector

any tips?

with thanks
User avatar
BobMuenchen
Posts: 16
Joined: Thu Jan 18, 2018 6:24 pm
Location: Knoxville
Contact:

Re: Compatability with R's with() function

Post by BobMuenchen »

Wow, that is freaky! I thought I knew a fair amount about with(), but I don't know why that's not giving you a list of the variables as will happen using:

> with(ToothGrowth, ls())
[1] "dose" "len" "supp"

I've tried every variation I can think of in creating a function and the only thing that doesn't screw it up is just a straight copy into a new function name. Here's what I know about how with() affects R's search order, though I don't know if there's a clue in that or not:

http://r4stats.com/2012/09/25/specifyin ... bles-in-r/
Post Reply