haghish / rcall

Seamless interactive R in Stata. rcall allows communicating data sets, matrices, variables, and scalars between Stata and R conveniently
http://www.haghish.com/packages/Rcall.php
91 stars 29 forks source link

too few quotes code error causes rcall to fail running #37

Closed ericmelse closed 3 months ago

ericmelse commented 6 months ago

Dear Ebad, I your TSJ paper you published example code to use a R-package, like on page 73 and 74:

program rplot
rcall vanilla: library(ggplot2); qplot(data=st.data(), `0´)
end

sysuse auto, clear
rplot mpg, price, colour = foreign, shape = foreign

When I run this code, what is returned is:

too few quotes
r(132);

which means that the code fails to run and makes rcall disfunctional.

I cannot explain from your examples where and why 'quotes' are required.

Can you explain what is the problem and how to resolve it?

Best regards, Eric

haghish commented 3 months ago

In Stata Journal, if I remember correctly, the grave accent had to be typed in a certain style that would not be executable in Stata itself, if you copy-paste it. Therefore, `0´ is not recognized by Stata, but `0' is recognized. So by correcting the accents, the example would run:

program rplot
rcall vanilla: library(ggplot2); qplot(data=st.data(), `0')
end

sysuse auto, clear
rplot mpg, price, colour = foreign, shape = foreign
ericmelse commented 3 months ago

Thank you again for your instruction. Now I use the following code:

program rplot
rcall vanilla: library(ggplot2); qplot(data=st.data(), `0')
end

rcall clear
rcall setpath "C:/Program Files/R441/bin/R.exe"
rcall: setwd("C:/Rcall")

sysuse auto, clear
rplot mpg, price, colour = foreign, shape = foreign

Which again produces the same error as I mentioned in the other post:

. rcall clear
(R memory cleared)

. rcall setpath "C:/Program Files/R441/bin/R.exe"

. rcall: setwd("C:/Rcall")
Warning message:
 In  :  
. 
. sysuse auto, clear
(1978 automobile data)

. rplot mpg, price, colour = foreign, shape = foreign
Warning message:
 In  :  

Furthermore, the figure is not produced as such in a R window (but maybe that is not expected and should I use code to save it as a file, e.g. png?). Maybe also the above is solved easily. Time permitting, I appreciate your suggestion to improve.

ericmelse commented 3 months ago

Also now, the above runs without the warning. But, again I do not see the rplot graphic in any window. Is that expected behavior? And, when that is indeed the case, how can I get it displayed, or, how can I get it to be exported (in the then current working folder)?