user1424739
user1424739

Reputation: 13745

How to call littler without sourcing ~/.Rprofile?

It seems that when I call littler from the command line, it will source ~/.Rprofile. Is there a way to prevent it from sourcing ~/.Rprofile?

Upvotes: 0

Views: 65

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368439

It goes both ways---that we are now reading ~/.Rprofile is in large part due to users who wanted this feature, as opposed to you not wanting it :)

But there is a (simple and easy) fix: use interactive(). Witness:

edd@rob:~$ r -e 'print(interactive())'
[1] FALSE
edd@rob:~$ r -i -e 'print(interactive())'

Please do not apply R like a magic answers box, because you can mislead
others and cause harm.
   -- Jeff Newmiller (about how much statistical knowledge is needed 
      for using R)
      R-help (May 2016)

[1] TRUE
edd@rob:~$ 

So what happened here? First, we tested interactive(). It came back FALSE. This is the default. Nothing happened.

Second, I added the -i switch to enfore interactive mode. It printed TRUE, but more. Why?

Well my ~/.Rprofile in essence looks like this

   ## header with a few constant settings, mostly to options()

   ## TZ setting and related

   local({     # start of large block, see Rprofile.site

   if (interactive()) {
      if (requireNamespace("fortunes", quietly=TRUE)) {
         print(fortunes::fortune()) 

         #more stuff

      }

   })

and that governs my interactive R sessions on the console, in Emacs/ESS, in RStudio, and my non-interactive r calls from, say, crontab.

So in short: yes, it is always read. But yes, you can also skip parts you do not want executed.

Upvotes: 1

Related Questions