Closed remlapmot closed 2 years ago
Thanks!
Tom, thanks for the update!
I found that code did not work for me, so I have extended it to search a few likely directories in case Stata is not on the executable search PATH.
If you wouldn’t mind, could you install this latest tweak and verify that it still works for you? Your code is still intact, and runs first.
From: Tom Palmer @.>
Sent: Sunday, February 20, 2022 12:40 PM
To: Hemken/Statamarkdown @.>
Cc: Subscribed @.***>
Subject: [Hemken/Statamarkdown] Small improvement to find_stata()
on Linux (PR #26)
I started using Linux again and taking some of the discussion from #6https://github.com/Hemken/Statamarkdown/pull/6 this hopefully improves find_stata() on Linux.
· tom:/usr/local/stata17$ ls -a
· . auto.dta installed.170 libstata-se.so stata stata.lic stata_pdf xstata
· .. docs isstata.170 libstata.so stata-mp stata17.png stinit xstata-mp
· ado inst2 libstata-mp.so setrwxp stata-se stata_br utilities xstata-se
At the moment when I load the package it just finds the stata executable (which obvs I could change in the options).
You can view, comment on, or merge this pull request online at:
https://github.com/Hemken/Statamarkdown/pull/26
Commit Summary
File Changes
(1 filehttps://github.com/Hemken/Statamarkdown/pull/26/files)
Patch Links:
— Reply to this email directly, view it on GitHubhttps://github.com/Hemken/Statamarkdown/pull/26, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACYBME4KBMNDS4IAYLWGAVDU4EYQJANCNFSM5O4YJZSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hi Doug (sorry for long reply - and apologies if you already know all of this)
I have been bitten by PATH
problems in R on Linux many times ... it took me a long time to discover the following.
PATH
environment variable in your Renviron.site
file (even if it's added in your .bashrc
or some other shell profile file or even .Renviron
file).This is because PATH
is different depending upon whether R is launched as a user or superuser (as rstudio-server
often is, e.g., it is when I run it under Windows Subsystem for Linux).
Initially, I added the /usr/local/stata-mp
directory to my PATH
in my .bashrc
file. Then launching R as user from bash
includes this directory in PATH
and all is fine.
However, if I launched R as a superuser with sudo R
(without adding to PATH
in either the .Renviron
or Renviron.site
files), then PATH
is only these few directories,
> Sys.getenv("PATH")
[1] "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
My best solution is to add the /usr/local/stata17
directory to PATH
in the Renviron.site
file, which is in ${R_HOME}/etc
(/usr/lib/R/etc
in my Ubuntu), with the line
PATH=${PATH}:/usr/local/stata17
Then PATH
in a sudo R
session is
> Sys.getenv('PATH')
[1] "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/stata17"
And so calling Sys.which("stata-mp")
in that finds stata-mp
and all is well.
A slightly less good solution is to amend PATH
in your .Renviron
file, however, I think that means the sudo R
/sudo rstudio-server
session must be launched from the same directory that .Renviron
file is in.
If I don't amend my PATH
in Renviron.site
/.Renviron
both my code and your code don't find stata-mp
under a sudo R
or sudo rstudio-sever
session because your additional directories don't include /usr/local/stata17
and that's not on PATH
.
So you could add /usr/local/stata17
(and perhaps /usr/local/stata16
and /usr/local/stata15
as well) to the additional directories you added.
And perhaps we should add an explanation about PATH
being different under R
and sudo R
/sudo rstudio-server
sessions to the helpfiles?
All best, Tom
I see! (You have discovered that I am recently using Statamarkdown in RStudio Server, nice detective work!) Thanks for the details. I am vaguely aware of some of these Linux configuration issues with other software, but had not investigated them with respect to Statamarkdown.
So I agree with you that:
From: Tom Palmer @.>
Sent: Thursday, March 3, 2022 5:06 AM
To: Hemken/Statamarkdown @.>
Cc: Doug Hemken @.>; State change @.>
Subject: Re: [Hemken/Statamarkdown] Small improvement to find_stata()
on Linux (PR #26)
Hi Doug (sorry for long reply - and apologies if you already know all of this)
I have been bitten by PATH problems in R on Linux many times ... it took me a long time to discover the following.
This is because PATH is different depending upon whether R is launched as a user or superuser (as rstudio-server often is, e.g., it is when I run it under Windows Subsystem for Linux).
Initially, I added the /usr/local/stata-mp directory to my PATH in my .bashrc file. Then launching R as user from bash includes this directory in PATH and all is fine.
However, if I launched R as a superuser with sudo R (without adding to PATH in either the .Renviron or Renviron.site files), then PATH is only these few directories,
Sys.getenv("PATH")
[1] "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
My best solution is to add the /usr/local/stata17 directory to PATH in the Renviron.site file, which is in ${R_HOME}/etc (/usr/lib/R/etc in my Ubuntu), with the line
PATH=${PATH}:/usr/local/stata17
Then PATH in a sudo R session is
Sys.getenv('PATH')
[1] "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/stata17"
And so calling Sys.which("stata-mp") in that finds stata-mp and all is well.
A slightly less good solution is to amend PATH in your .Renviron file, however, I think that means the sudo R/sudo rstudio-server session must be launched from the same directory that .Renviron file is in.
If I don't amend my PATH in Renviron.site/.Renviron both my code and your code don't find stata-mp under a sudo R or sudo rstudio-sever session because your additional directories don't include /usr/local/stata17 and that's not on PATH.
So you could add /usr/local/stata17 (and perhaps /usr/local/stata16 and /usr/local/stata15 as well) to the additional directories you added.
And perhaps we should add an explanation about PATH being different under R and sudo R/sudo rstudio-server sessions to the helpfiles?
All best, Tom
— Reply to this email directly, view it on GitHubhttps://github.com/Hemken/Statamarkdown/pull/26#issuecomment-1057931822, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACYBMEZKX2WRYG22WPLYMG3U6CMIVANCNFSM5O4YJZSA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you modified the open/close state.Message ID: @.***>
I started using Linux again and taking some of the discussion from #6 this hopefully improves
find_stata()
on Linux.I changed calling
which
from usingsystem2()
to usingSys.which()
.I also added the additional executable names as discussed (searching in order:
stata-mp
,stata-se
,stata
,stata-ic
). For info the Stata 17 directory on my Linux installation has nostata-ic
but maybe an earlier version used that name (I'm not sure), it's contents areAt the moment when I load the package it just finds the
stata
executable (which obvs I could change in the options).