Skip to content

Instantly share code, notes, and snippets.

@cgpu
Last active December 28, 2018 03:22
Show Gist options
  • Save cgpu/4449a58cfb31db04099f2879673e3e69 to your computer and use it in GitHub Desktop.
Save cgpu/4449a58cfb31db04099f2879673e3e69 to your computer and use it in GitHub Desktop.
How to source .R scripts from github; works for (i) .R scripts stored in projects' repos or (ii) .R scripts saved as gists.
title author date output
How to source .R scripts from github; works for (i) .R scripts stored in projects' repos or (ii) .R scripts saved as gists.
cgpu
html_document
toc toc_depth toc_float number_sections theme highlight
true
3
true
false
united
tango

Locate GitHub hosted .R script

  1. Click on raw
  2. Copy URL

Utilise the devtools::source_url function

# Check if/Have `devtools` R package installed;
if (!require("devtools")) install.packages("devtools")

Store .R script's url in a variable;

Do not omit the 'https://' part of the url

URL = "https://raw.githubusercontent.com/cran/gower/master/R/gower.R"

Source .R script remotely with devtools::source_url

devtools::source_url(URL)

Call a function from your script:

gower_work(
           x       = .. , 
           y       = .. , 
           pair_x  = .. , 
           pair_y  = .. , 
           n       = .. , 
           eps     = .. , 
           nthread = ..
           )
@cgpu
Copy link
Author

cgpu commented Oct 20, 2018

Locate GitHub hosted .R script

  1. Click on raw
  2. Copy URL

Utilise the source.gist() function from the R package installr

# Check if/Have `installr` R package installed;
if (!require("installr")) install.packages("installr")

Store .R script's url in a variable;

Do not omit the 'https://' part of the url

URL = "https://raw.githubusercontent.com/cran/gower/master/R/gower.R"

Source .R script remotely with source.gist()

installr::source.git(URL)

Call a function from your script:

gower_work(
           x       = .. , 
           y       = .. , 
           pair_x  = .. , 
           pair_y  = .. , 
           n       = .. , 
           eps     = .. , 
           nthread = ..
           )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment