Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In file(con, "r"): cannot open file 'RStata.log': No such file or directory #2

Closed
mikejacktzen opened this issue Sep 23, 2015 · 12 comments

Comments

@mikejacktzen
Copy link

I've tried your instructions and run into an error

# library(devtools)
# install_github("lbraglia/RStata")

library(RStata)

# "C:\Program Files (x86)\Stata13\StataMP-64.exe"
# stata_path = "C:\\Program Files (x86)\\Stata13\\StataMP-64"

options("RStata.StataPath" = "C:\\Program Files (x86)\\Stata13\\StataMP-64.exe")
options("RStata.StataPath" = "C:\\Program Files (x86)\\Stata13\\StataMP-64")
options("RStata.StataPath" = "C:\\Program Files (x86)\\Stata13\\")

# I tried all three above. Your documentation is not clear on what the syntax should be for the path of the stata executable

options("RStata.StataVersion" = 13)
stata(c("set obs 200", "gen a = 1"))

Warning message:
In file(con, "r"): cannot open file 'RStata.log': No such file or directory

Error in file(con, "r"): cannot open the connection
@lbraglia
Copy link
Owner

It could be a windows-quote problem. Can you use chooseStataBin and set RStata.StataPath to the string reported?

let me know

@lbraglia
Copy link
Owner

closing in 7 days (more or less) from today...

@lbraglia lbraglia closed this as completed Nov 5, 2015
@bprest
Copy link

bprest commented Jun 15, 2016

I had the same issue. I used chooseStataBin() and set it as you suggested. I tried single quotes and double quotes, and the same result occurred. Running Windows 10, Stata 12.

> library(RStata)
> chooseStataBin()
[1] "C:\\Program Files (x86)\\Stata12\\StataSE-64"
> options("RStata.StataVersion"=12)
> options("RStata.StataPath")
$RStata.StataPath
[1] "C:\\Program Files (x86)\\Stata12\\StataSE-64"

> options("RStata.StataVersion")
$RStata.StataVersion
[1] 12

> stata(c("set obs 200", "gen a = 1"))
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'RStata.log': No such file or directory

R.version specs:

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          2.3                         
year           2015                        
month          12                          
day            10                          
svn rev        69752                       
language       R                           
version.string R version 3.2.3 (2015-12-10)
nickname       Wooden Christmas-Tree   

@mikejacktzen
Copy link
Author

still have issues,
now on windows 10 using stata 14.
i've never got passed this stage for any platform i've tried

install.packages('RStata')

library(RStata)

options("RStata.StataVersion" = 14)

chooseStataBin()

options("RStata.StataPath")

# Windows stata shortcut target path

# single slash
# stata_path = "C:\Program Files (x86)\Stata14\StataSE-64.exe"
# stata_path = "C:\Program Files (x86)\Stata14\StataSE-64"
# 
options("RStata.StataPath")


stata_path = "C:\\Program Files (x86)\\Stata14\\StataSE-64"
stata_path = "C:\\Program Files (x86)\\Stata14\\StataSE-64_old"
stata(stata.path=stata_path,
      c("set obs 200", "gen a = 1"))
options("RStata.StataPath"=stata_path)
stata(c("set obs 200", "gen a = 1"))

stata_path = "C:\\Program Files (x86)\\Stata14\\StataSE-64.exe"
stata_path = "C:\\Program Files (x86)\\Stata14\\StataSE-64_old.exe"
stata(stata.path=stata_path,
      c("set obs 200", "gen a = 1"))
options("RStata.StataPath"=stata_path)
stata(c("set obs 200", "gen a = 1"))

stata_path = "C:/Program Files (x86)/Stata14/StataSE-64"
stata_path = "C:/Program Files (x86)/Stata14/StataSE-64_old"
stata(stata.path=stata_path,
      c("set obs 200", "gen a = 1"))
options("RStata.StataPath"=stata_path)
stata(c("set obs 200", "gen a = 1"))

stata_path = "C:/Program Files (x86)/Stata14/StataSE-64.exe"
stata_path = "C:/Program Files (x86)/Stata14/StataSE-64_old.exe"
stata(stata.path=stata_path,
      c("set obs 200", "gen a = 1"))
options("RStata.StataPath"=stata_path)
stata(c("set obs 200", "gen a = 1"))

sessionInfo()
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RStata_1.0.0

loaded via a namespace (and not attached):
[1] tools_3.3.1    foreign_0.8-66

@lbraglia lbraglia reopened this Aug 30, 2016
@lbraglia
Copy link
Owner

lbraglia commented Aug 30, 2016

Umm,

at the time i wrote the function i tested it on Windows XP (and 7) with both Stata 13 (SE 64bit) and Stata 8 (SE 32) and from what i remember it worked fine.

Unfortunately i've no machine running Windows 10 (i'm not a Windows daily user...) at the time.

Anyway RStata uses Stata batch mode in Windows: could you please test if you can run a do file in batch mode with the /e parameter?

http://www.stata.com/manuals14/gswb.pdf#gswB.5

Another guy who contacted me via e-mail said to have a similar problem and the reason was that his Stata version didn't support batch execution.

Regarding other operating systems:

  • I use it currently on Linux with no problems;
  • for Mac there should be some (minimal) additional efforts in the config (some hints available in the README.md) but i ran successfully RStata on el capitan + stata 13 SE 64bit

@mikejacktzen
Copy link
Author

http://www.stata.com/manuals14/gswb.pdf#gswB.5

Method 2
If you do not really care where the log file should be after your job is done, and you are allowed
to write to the directory where Stata is installed, then use the same method as above but skip the cd
step. This is not generally recommended.

Pretty sure the above is the root of the problem on the windows side.

Windows installs stata into say,
"C:\Program Files (x86)\Stata14\StataSE-64"
by default, there are NO write permissions

i'm guessing your Rstata uses "Method 2" above, which tries to output the 'foo.log' file into the
unwriteable default Stata directory.

On another Note, I tried "Method 1" which runs fine for stata (outputs a 'foo.log' file successfully) into the user specified "...\statalogs" directory

cd C:\Users\someone\statalogs
"C:\Program Files\Stata14\StataSE.exe" /e do "C:\Users\someone\statastuff\bigjob"

I suggest adding an option to "Rstata" that lets us choose the "\statalog" directory which plays nicely with Method 1 above. This sidesteps the probable issue we're seeing here.

This would be for people that can not modify the write permissions of the default stata directory.

@lbraglia
Copy link
Owner

lbraglia commented Sep 2, 2016

i'm going on holiday; i'll check it a bit more in deep when i come back

@lbraglia
Copy link
Owner

@mikejacktzen @bprest could you test the development version now and tell me how it goes?

remove.packages('RStata')
devtools::install_github('lbraglia/RStata')

thanks

@bprest
Copy link

bprest commented Sep 14, 2016

It works on my colleague's machine! Unfortunately it won't even install on mine for some reason, but I believe this is a local problem.

@mikejacktzen
Copy link
Author

Great! works for me on windows 10 with StataSE14

remove.packages('RStata')
devtools::install_github('lbraglia/RStata')

library(RStata)

options("RStata.StataVersion" = 14)

chooseStataBin()
options("RStata.StataPath")
# [1] "\"C:\\Program Files (x86)\\Stata14\\StataSE-64\""

# explicit path
stata_path = "\"C:\\Program Files (x86)\\Stata14\\StataSE-64\""

stata(stata.path=stata_path,
      c("set obs 200", "gen a = 1"))

stata_src = "
version 10
sysuse auto
reg mpg weight
"
stata(stata.path=stata_path,
      stata_src)

sessionInfo()

# > sessionInfo()
# R version 3.3.1 (2016-06-21)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows >= 8 x64 (build 9200)
# 
# locale:
#   [1] LC_COLLATE=English_United States.1252 
# [2] LC_CTYPE=English_United States.1252   
# [3] LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C                          
# [5] LC_TIME=English_United States.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] RStata_1.0.0
# 
# loaded via a namespace (and not attached):
#   [1] tools_3.3.1    foreign_0.8-66

@lbraglia
Copy link
Owner

Fine. It was a Windows path quoting problem that i missed the last time.

I've submitted the patched version (1.1.0) to CRAN; it should be available for easy download/install soon.

best, Luca

@ractingmatrix
Copy link

Hello, sorry to dig this out but I m still getting a similar problem. I m using R to do loops involving use of rstata. Each of the loops execute rstata. The loops generally go on fine and successful executeed many loops until some time later there was ab error "unable to open `C:\mydofilefolder\Rstata.log' ".

So the loops sometimes work , sometimes don't. Grateful for any advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants