Skip to content

.Rprofile with devtools::install_github() loops

3 messages · Bill Dunlap, Chris Evans

#
I am sure this must be documented somewhere and that I'm missing something obvious but some searching isn't finding an answer and I'm sure there is one.

I have created a very simple package on GitHub and want my machines (other than the one that built it) to load it when they start R using devtools::install_github()

The install_github() call works fine from the console but when I put it in my .Rprofile it just loops on restarting R.  I _think_ it may be that devtools::install_github()
is restarting the session as I found one thing on the web suggesting that may be the case.  However, I think if it were the case it would be documented and I'd find
far more about that.

OK.  So my .Rprofile is:

print("This is a message from /home/chris/.Renviron: hello Chris!")
.First <- function(){
    devtools::install_github("xxxx/yyyy")
}
print("OK, off you go!")

I have obscured my package to protect my blushes but I get the same behaviour with r-lib/devtools and, as I say, my little package loads OK from the console.

You can see I tried wrapping it in a .First() function but that didn't change anything.

True both on a Linux machine and a Windows machine.

OK.  Anyone save me from more dents in the wall and frontal lobe damage?!

TIA,

Chris
#
Installing a package involves running several R subprocesses, each of
which is running that .Rprofile.  You may be able to stop the infinite
recursion by setting an environment variable that subprocesses can
check.  E.g. replace
  install_github("xxx/yyy")
with
  if (Sys.getenv("INSTALLING_FROM_GITHUB", unset="no") == "no") {
    Sys.setenv(INSTALLING_FROM_GITHUB="yes")
    install_github("xxx/yyy")
  }

[This is totally untested.]

-Bill
On Wed, Feb 10, 2021 at 12:45 AM Chris Evans <chrishold at psyctc.org> wrote:
#
Works perfectly.  Brilliant.

I have added this, with appreciation to you Bill, to my "post" about creating my first (and probably only!) R package at:

https://www.psyctc.org/Rblog/posts/2021-02-10-making-my-first-usable-package/

Thanks Bill, very best all,

Chris

----- Original Message -----