Closed dalewsteele closed 8 years ago
Note, works without error on Linux Stata 14.2
in Windows with
stata("sysuse auto", data.out = TRUE, stata.version = 14.2)
stata
(function) put this save command at the end of the do file
saveold RStataDataOut, version(12)
which should be perfectly fine to save an R-readable (with foreign) file. Could you try (in your Windows Stata)
sysuse auto
saveold autotest, version(12)
and let me know if it's R-readable with foreign::read.dta
?
Yes, I can read the autotest.dta file saved in version 12 (using Windows Stata) format using foreign::read.dta.
What did you set up for
options("RStata.StataVersion")
?
> options("RStata.StataVersion")
$RStata.StataVersion
[1] 14
`
could you
debug(stata)
auto <- stata("sysuse auto", data.out = TRUE)
and step until
https://github.com/lbraglia/RStata/blob/master/R/stata.R#L155
then post the content of the SRC variable?
Thanks for your patience. I tried this on my Windows 7 laptop with Stata 14 and cannot reproduce the error.
Will try debug(stata) on my work desktop running Windows 8 that generates the error.
Hmmm. I re-ran the code below (Windows 8, Stata 14, Microsoft R Open 3.3.1) within RStudio v1.0.19)
auto <- stata("sysuse auto", data.out = TRUE)
Works as expected without error!
However, when I run from Windows R conole, I still still get the error.
> auto <- stata("sysuse auto", data.out=TRUE)
. sysuse auto
(1978 Automobile Data)
Error in foreign::read.dta(dtaOutFile, ...) :
not a Stata version 5-12 .dta file
Will try debug(stata) ...
Output from debug(stata) below (in R consolate)
Browse[2]> n
debug: SRC <- c({
if (dataIn) sprintf("use %s", tools::file_path_sans_ext(dtaInFile)) else ""
}, "capture noisily {", cut_me_comment, SRC, cut_me_comment,
"} /* end capture noisily */")
Browse[2]> SRC
[1] "sysuse auto"
you stopped too early with debug... you should press enter until you get something like
debug: SRC <- c(SRC, "exit, clear STATA")
then display the content of SRC
OK, thanks. See below:
Browse[2]> n
debug: SRC <- c(SRC, "exit, clear STATA")
Browse[2]> SRC
[1] "set more off" "" "capture noisily {"
[4] "/*RSTATA: cut me here*/" "sysuse auto" "/*RSTATA: cut me here*/"
[7] "} /* end capture noisily */" "saveold RStataDataOut, version(12)"
Does this come from the R standard console? You can see that RStata does what it's intended to do; the last line is
saveold RStataDataOut, version(12)
which is the right Stata command to produce a version 12 dta.
Yes, I ran debug(stata) and produced the output for the 'SRC' object in the R console. Very strange. Appreciate your help. Not sure it's worth spending time on since the error does hot happen on the same machine when I run R via RStudio.
Yes very strange ... ok, thanks anyway for multi-platform/interpreters testing.
I'm using RStata on a Windows 8 machine running Stata/IC 14.2. The code below fails, apparently because data is read using package{foreign} that does not recognize a Stata version 14 .dta file.
Is this an argument to use haven (which can read these files)?