Re-l
Re-l

Reputation: 301

How to keep modified/downloaded package

R noobie here.

I'm am trying to use a package that I download off of github using source_gist, but it appears that I need to re-download it every time I quit R (I'm using RStudio).

To clarify, the function that I'm using is part of plotrix package and is called barp. Someone made a modified version of it (called barp2) and put it up on github. That's what I want to use.

So my question is this: is there anyway to have this modified code saved inside the plotrix package, so I wouldn't have to download it every time?

I hope I'm explaining this correctly.

enter image description here

Upvotes: 0

Views: 41

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 146070

So, let's get some quick terminology straight: the function you're getting off of github isn't a package, it's just a single function. If it was a package, you could use devtools::install_github once and then load it with require() or library() like any other package.

A good solution isn't too different. Just go to the gist, copy the code, paste it into your R editor, and save it somewhere as a .R script file. Something like C:/path/to/barp2.R (adjusting, of course, based on where you actually want to keep it and based on your OS). Then you can read it locally using source("C:/path/to/barp2.R") instead of devtools::source_gist().

If you always want to load it, you could load plotrix and then source this file every time R starts with a couple lines in your R profile, see ?Startup as @BondedDust suggests for details on this.

Reading it off of github every time does have the advantage that, if the author fixes bugs or otherwise improves it, you'll always be using the up-to-date version. It has several disadvantages too: requiring an internet connection, losing access if the gist is deleted, or being unable to access old versions if the author changes it in a way you don't like. Keeping a copy of a version you like is a smart move.

Upvotes: 3

Related Questions