Created
June 18, 2015 21:11
-
-
Save junhe/1f7e41f4c2829486e46f to your computer and use it in GitHub Desktop.
This is a file I should source in R markdown code block, so I can use it to run R code in my private github repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function download my python downloader, and use the downloader to download | |
# the private file from github repository. | |
# Example: | |
# source_private_github_file("doraemon", "analysis/analyzer.r", "599060f45d97538b9dffda4b54ab88d1e7eff006") | |
source_private_github_file <- function(repo_name, file_path, commit) | |
{ | |
target_dir = "/tmp/dir_for_source_private_github_file_x32nd83sx" | |
# download the downloader | |
print("downloading the python downloader..") | |
system('cd /tmp; curl -O https://gist.githubusercontent.com/junhe/806c57ce629e1d7035a1/raw/download_github_private_file.py') | |
# execute the downloader | |
print("downloading the private file using python downloader...") | |
cmd = sprintf("source ~/.profile; python /tmp/download_github_private_file.py --repo_name %s --file_path %s --target_dir %s --commit %s", | |
repo_name, file_path, target_dir, commit) | |
system(cmd) | |
basename = tail(unlist(strsplit(file_path, "/")), n=1) | |
local_path = paste(target_dir, basename, sep="/") | |
# sourcing the downloaded file | |
print(paste("sourcing the downloaded file:", local_path)) | |
source(local_path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment