Page 1 of 1
					
				Compatability with R's with() function
				Posted: Tue Feb 27, 2018 2:34 pm
				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)
			 
			
					
				Re: Compatability with R's with() function
				Posted: Tue Feb 27, 2018 10:29 pm
				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 

)
 
			 
			
					
				Re: Compatability with R's with() function
				Posted: Wed Feb 28, 2018 6:26 pm
				by BobMuenchen
				Thanks!
			 
			
					
				Re: Compatability with R's with() function
				Posted: Thu Mar 01, 2018 12:30 am
				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
 
			 
			
					
				Re: Compatability with R's with() function
				Posted: Thu Mar 01, 2018 1:34 pm
				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/