There are some built-in functions in papercheck for exploring GitHub repositories. You can use these in custom modules.
github_repo
The github functions all work with the following formats for referring to repositories:
-
"{username}/{repo}"
-
"{username}/{repo}.git"
-
"https://github.com/{username}/{repo}.git"
"https://github.com/{username}/{repo}/{...}"
The github_repo()
function returns the simplified format
of. repo name, and an error if the repository in inaccessible.
github_repo("https://github.com/scienceverse/papercheck.git")
#> [1] "scienceverse/papercheck"
github_repo("scienceverse/checkpaper")
#> Error in github_repo("scienceverse/checkpaper"): scienceverse/checkpaper is unavailable
github_readme
Get the text of the readme file, regardless of the exact file name (e.g., README vs README.md).
readme <- github_readme("scienceverse/papercheck")
cat(readme)
#> # papercheck
#>
#> The goal of papercheck is to automatically check scientific papers for best practices. You can find out more at <https://scienceverse.github.io/papercheck/>.
#>
#> ## Installation
#>
#> You can install the development version of papercheck from [GitHub](https://github.com/) with:
#>
#> ``` r
#> # install.packages("devtools")
#> devtools::install_github("scienceverse/papercheck")
#> ```
github_languages
You can retrieve the number of bytes dedicated to various coding languages, as detected and classified by GitHub.
github_languages("scienceverse/papercheck")
#> language bytes
#> 1 R 232339
#> 2 AMPL 8327
#> 3 Python 6986
#> 4 CSS 3358
#> 5 JavaScript 1018
#> 6 SCSS 19
github_files
You can get a list of file names, their path, size, file extension, and a guess at their type.
By default, you just retrieve the files and directories in the base directory, non-recursively.
github_files("scienceverse/papercheck")
#> name path size ext type
#> 1 .github .github 0 github dir
#> 2 .gitignore .gitignore 183 gitignore config
#> 3 .Rbuildignore .Rbuildignore 168 rbuildignore file
#> 4 data data 0 dir
#> 5 data-raw data-raw 0 dir
#> 6 DESCRIPTION DESCRIPTION 1583 file
#> 7 inst inst 0 dir
#> 8 LICENSE LICENSE 48 file
#> 9 LICENSE.md LICENSE.md 1077 md text
#> 10 man man 0 dir
#> 11 NAMESPACE NAMESPACE 1051 file
#> 12 NEWS.md NEWS.md 2842 md text
#> 13 papercheck.Rproj papercheck.Rproj 462 rproj config
#> 14 pkgdown pkgdown 0 dir
#> 15 profile profile 0 dir
#> 16 R R 0 dir
#> 17 README.md README.md 379 md text
#> 18 tests tests 0 dir
#> 19 vignettes vignettes 0 dir
github_files("scienceverse/papercheck", dir = ".github")
#> name path size ext type
#> 1 .gitignore .github/.gitignore 7 gitignore config
#> 2 workflows .github/workflows 0 dir
You can also retrieve files recursively. Searching a large repository recursively can take a few seconds.
github_files("scienceverse/papercheck",
dir = ".github",
recursive = TRUE)
#> name path size ext type
#> 1 .gitignore .github/.gitignore 7 gitignore config
#> 2 workflows .github/workflows 0 dir
#> 3 pkgdown.yaml .github/workflows/pkgdown.yaml 1304 yaml config
github_info
Get all of the information about a repository in one list object, with items named “repo”, “readme”, “languages”, and “files”.
info <- github_info("scienceverse/papercheck",
recursive = TRUE)
info$files |> dplyr::count(type)
#> type n
#> 1 audio 16
#> 2 code 426
#> 3 config 7
#> 4 data 9
#> 5 dir 33
#> 6 file 4
#> 7 image 11
#> 8 text 18
#> 9 web 4