diff --git a/R.ado b/R.ado index 80b29b7..12aa5df 100644 --- a/R.ado +++ b/R.ado @@ -1,7 +1,7 @@ // documentation written for markdoc /*** -[Version: 3.0.5](https://github.com/haghish/rcall/tags) +[Version: 3.1.0](https://github.com/haghish/rcall/tags) cite: [Haghish, E. F. (2019). Seamless interactive language interfacing between R and Stata. The Stata Journal, 19(1), 61-82.](https://journals.sagepub.com/doi/full/10.1177/1536867X19830891) @@ -416,8 +416,13 @@ program define R , rclass // drop the macros // ------------------------------------------------------------------------- - macro drop RcallError + + // check the working directory permission + // -------------------------------------- + if missing("$wdpermissions") { + wdpermissions + } // ------------------------------------------------------------------------- // Search R path, if not specified @@ -540,6 +545,7 @@ program define R , rclass // clear the rcall global memory that is used for data transfer macro drop rcallglobal* macro drop rcall_synchronize_mode + macro drop wdpermissions display as txt "(R memory cleared)" exit @@ -764,6 +770,7 @@ program define R , rclass local 0 : subinstr local 0 ":" "" } } + // ------------------------------------------------------------------------- // Execute interactive mode (including sync) @@ -1118,7 +1125,7 @@ program define R , rclass } if !missing("`vanilla'") file write `knot' "rm(list=ls())" _n // erase memory temporarily - if !missing("`foreign'") file write `knot' "library(readstata13)" _n // load the readstata13 package + if !missing("`foreign'") file write `knot' "suppressWarnings(library(readstata13))" _n // load the readstata13 package if !missing("`RSite'") & missing("`vanilla'") /// file write `knot' "source('`RSite'')" _n if !missing("`rprofile'") & missing("`vanilla'") /// diff --git a/dependency.do b/dependency.do index f768ad4..0828a27 100644 --- a/dependency.do +++ b/dependency.do @@ -8,5 +8,12 @@ R packages. If the installation fails, read the rcall help file and install the dependencies manually. ***/ +// check github version and require minimum of version 2.3.0 +quietly github version github +if "`r(version)'" < "2.2.0" { + di as err "please update your GitHub package" + di as txt "type: github update github" +} + rcall_check rcall: install.packages("readstata13", repos="http://cran.us.r-project.org") diff --git a/examples/Article Examples/rplot.ado b/examples/Article Examples/rplot.ado index 85a4e76..8985a0d 100644 --- a/examples/Article Examples/rplot.ado +++ b/examples/Article Examples/rplot.ado @@ -1,17 +1,14 @@ -// summary program -// =============== -// -// carring the "summary" function in R to summarize data in Stata +// Using the qplot R function in Stata +// =================================== -*cap prog drop rplot program rplot - version 12 - syntax varlist [, colour(name) shape(name) format(name)] + version 14 + syntax varlist [, filename(name) colour(name) shape(name) format(name)] // check for the required packages and versions // ------------------------------------------------------------------------- - rcall_check ggplot2>=2.1.0 , r(3.1.0) rcall(1.3.3) + rcall_check ggplot2>=2.1.0 , r(3.1.0) rcall(2.5.0) // Checking the variables // ------------------------------------------------------------------------- @@ -37,12 +34,13 @@ program rplot local colour ", colour = `colour'" } if !missing("`shape'") local shape ", shape = `shape'" + if missing("`filename'") local filename Rplot if missing("`format'") local format pdf - rcall vanilla : `format'("Rplot.`format'"); library(ggplot2); /// - qplot(data=st.data(), x =`2', y =`1' `colour' `shape') + rcall vanilla : `format'("`filename'.`format'"); library(ggplot2); /// + qplot(data=st.data(), x =`2', y =`1' `colour' `shape') di as txt "({browse Rplot.`format'} was produced)" end -*qplot price mpg , colour(foreign) shape(foreign) format(pdf) +*rplot price mpg , filename(graph) colour(foreign) shape(foreign) format(png) diff --git a/examples/Article Examples/summary.ado b/examples/Article Examples/summary.ado index 642ee24..6569139 100644 --- a/examples/Article Examples/summary.ado +++ b/examples/Article Examples/summary.ado @@ -2,12 +2,15 @@ // summary program // =============== // -// carring the "summary" function in R to summarize data in Stata +// Using the "summary" function in R to summarize data in Stata program summary, byable(recall) version 12 syntax varlist [if] [in] marksample touse + + rcall_check , rversion(3.0) rcall(2.5.0) //required rcall version and R version + preserve quietly keep if `touse' quietly keep `varlist' @@ -17,8 +20,10 @@ end // Examples /* -by foreign: summary price mpg -summary price mpg if price < 4500 +sysuse auto, clear +by foreign: summary price mpg if price < 4500 summary mpg weight if foreign==1 summary price mpg if mpg>25 & mpg<30 summary price mpg in 1/20 +*/ + diff --git a/examples/script/rscriptexample.R b/examples/script/rscriptexample.R new file mode 100644 index 0000000..58b7523 --- /dev/null +++ b/examples/script/rscriptexample.R @@ -0,0 +1,5 @@ +# This is a regular R script file +print(dim(df)) +correlation = cor(df$price, df$mpg) +mat2 = mat^2 +print(mat2) diff --git a/make.do b/make.do index 8cc1548..bd5b8a5 100644 --- a/make.do +++ b/make.do @@ -3,7 +3,7 @@ // DO NOT FORGET to update the version of the package, if changed! // for more information visit http://github.com/haghish/github -make rcall, replace toc pkg version(3.0.5) /// +make rcall, replace toc pkg version(3.1.0) /// license("MIT") /// author("E. F. Haghish") /// email("haghish@med.uni-goettingen.de") /// diff --git a/rcall.ado b/rcall.ado index e53f790..7ec5089 100644 --- a/rcall.ado +++ b/rcall.ado @@ -1,7 +1,7 @@ // documentation written for markdoc /*** -[Version: 3.0.6](https://github.com/haghish/rcall/tags) +[Version: 3.1.0](https://github.com/haghish/rcall/tags) cite: [Haghish, E. F. (2019). Seamless interactive language interfacing between R and Stata. The Stata Journal, 19(1), 61-82.](https://journals.sagepub.com/doi/full/10.1177/1536867X19830891) @@ -416,8 +416,13 @@ program define rcall , rclass // drop the macros // ------------------------------------------------------------------------- - macro drop RcallError + + // check the working directory permission + // -------------------------------------- + if missing("$wdpermissions") { + wdpermissions + } // ------------------------------------------------------------------------- // Search R path, if not specified @@ -540,6 +545,7 @@ program define rcall , rclass // clear the rcall global memory that is used for data transfer macro drop rcallglobal* macro drop rcall_synchronize_mode + macro drop wdpermissions display as txt "(R memory cleared)" exit @@ -764,6 +770,7 @@ program define rcall , rclass local 0 : subinstr local 0 ":" "" } } + // ------------------------------------------------------------------------- // Execute interactive mode (including sync) diff --git a/rcall.pkg b/rcall.pkg index f1248f8..12c59c2 100644 --- a/rcall.pkg +++ b/rcall.pkg @@ -1,9 +1,9 @@ -v 3.0.6 +v 3.1.0 d 'RCALL': seamless R in Stata d d call R in Stata and enable automated data communication d -d Distribution-Date: 20210810 +d Distribution-Date: 20210920 d License: MIT d F R.ado diff --git a/rcall.sthlp b/rcall.sthlp index c17671e..19be909 100644 --- a/rcall.sthlp +++ b/rcall.sthlp @@ -1,5 +1,5 @@ {smcl} -{browse "https://github.com/haghish/rcall/tags":Version: 3.0.6} +{browse "https://github.com/haghish/rcall/tags":Version: 3.1.0} {p 4 4 2} cite: {browse "https://journals.sagepub.com/doi/full/10.1177/1536867X19830891":Haghish, E. F. (2019). Seamless interactive language interfacing between R and Stata. The Stata Journal, 19(1), 61-82.} diff --git a/stata.toc b/stata.toc index 6012513..7a153f0 100644 --- a/stata.toc +++ b/stata.toc @@ -1,4 +1,4 @@ -v 3.0.6 +v 3.1.0 d Materials by E. F. Haghish d haghish@med.uni-goettingen.de d http://github.com/haghish