Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list files from a github repository folder using R

Tags:

github

r

I am wondering if there exists a function or a link or any method that would work like list.files() function in R but on a folder stored on a github repostiory.

example github repository folder: https://github.com/KZPS/Spotkania/tree/master/Matteo/literature

Thanks for any advice !

like image 961
Marcin Kosiński Avatar asked Aug 25 '14 11:08

Marcin Kosiński


1 Answers

Here's one way:

library(httr)
req <- GET("https://api.github.com/repos/KZPS/Spotkania/git/trees/master?recursive=1")
stop_for_status(req)
filelist <- unlist(lapply(content(req)$tree, "[", "path"), use.names = F)
grep("Matteo/literature/", filelist, value = TRUE, fixed = TRUE)
# [1] "Matteo/literature/Subsetting.pdf"     
# [2] "Matteo/literature/datatable-intro.pdf"

You could easily build a function list.files.github from that.

like image 105
lukeA Avatar answered Dec 25 '22 19:12

lukeA