[BlindRUG] Simple tip for automatic loading package

Godfrey, Jonathan A.J.Godfrey at massey.ac.nz
Thu Dec 3 23:01:03 UTC 2015


Hello all,

Like many things in R there are a number of ways to get a package loaded at the start of a session.

If there was more than one package to get loaded, then creation of an .Rprofile file is the way to go. A much quicker way (good for one package) would be to open the R session in the working directory you want to use.

Then type the single line:

.First=function(){library(BrailleR)}

Which will establish a function that will get processed when R is opened in this directory next time. It will overwrite an existing .First function if it had already been created. Note that you will not see the .First object when you use ls() because it is a hidden function. You will need to save the workspace on exit to ensure this command takes effect next time you start R in that directory.

The creation of the profile is actually already included in BrailleR in the function MakeRprofile(). I have just added the additional line that ensures all the default packages are loaded to this function, but this was happening successfully without the line on my machine already. (Thanks for the suggestion.)

Note: I recommend that you do not add the loading of BrailleR to a site wide Rprofile as problems can arise with package maintenance started in directories that have add-on packages loaded.

Jonathan


From: BlindRUG [mailto:blindrug-bounces at nfbnet.org] On Behalf Of JooYoung Seo via BlindRUG
Sent: Friday, 4 December 2015 8:20 a.m.
To: 'Blind R Users Group'
Cc: JooYoung Seo
Subject: [BlindRUG] Simple tip for automatic loading package

  Hi all,
  I am sharing simple tip you can use for loading any library or function automatically when starting up R.
  Some of you might face errors if you just tried to add code lines into .Rprofile (in your working directory) or /home/ect/Rprofile.site.
  Since all default packages should be loaded before your personalized setting, you need to call .First.sys() function before desired libraries.
  The following example is what you might want to do to get R to automatically load BrailleR package when starting the program:

#             # I will explain it for Window users, but other OS users also can apply it.

##1. Launch Notepad and type the below:

.First.sys() # this is what you need for loading all needed default packages before your script.
library(BrailleR) # loading BrailleR package
# You can add any other library or script as much as you want below.

##2. Save it to your working directory. Select "save as file type" as "all files *". And filename must be ".Rprofile" without quotes.

  I hope it would be helpful.
  Thanks.
  Sincerely,

       JooYoung

       JooYoung Seo
--------------------
  Graduate Student,
  Learning, Design, and Technology
  Learning and Performance Systems
  The Pennsylvania State University
  Phone: +1 (814) 777-5836
  E-mail: jzs323 at psu.edu<mailto:jzs323 at psu.edu>


________________________________
[Avast logo]<https://www.avast.com/antivirus>


This email has been checked for viruses by Avast antivirus software.
www.avast.com<https://www.avast.com/antivirus>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nfbnet.org/pipermail/blindrug_nfbnet.org/attachments/20151203/4d8010f7/attachment.html>


More information about the BlindRUG mailing list