Skip to content

Commit 4a6075d

Browse files
authored
Merge pull request #18 from nuest/master
Update report template and vignette, add tests, update register output, support multiple repo types
2 parents 828ee74 + 3d471fd commit 4a6075d

40 files changed

+881
-145
lines changed

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
33
^README\.Rmd$
4+
^\.httr-oauth$
5+
^\.travis\.yml$
6+
^\.github$

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/R-CMD-check.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
2+
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
name: R-CMD-check
12+
13+
jobs:
14+
R-CMD-check:
15+
runs-on: ${{ matrix.config.os }}
16+
17+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
config:
23+
- {os: windows-latest, r: 'release'}
24+
- {os: macOS-latest, r: 'release'}
25+
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
26+
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
27+
28+
env:
29+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
30+
RSPM: ${{ matrix.config.rspm }}
31+
32+
steps:
33+
- uses: actions/checkout@v2
34+
35+
- uses: r-lib/actions/setup-r@master
36+
with:
37+
r-version: ${{ matrix.config.r }}
38+
39+
- uses: r-lib/actions/setup-pandoc@master
40+
41+
- name: Query dependencies
42+
run: |
43+
install.packages('remotes')
44+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
45+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
46+
shell: Rscript {0}
47+
48+
- name: Cache R packages
49+
if: runner.os != 'Windows'
50+
uses: actions/cache@v1
51+
with:
52+
path: ${{ env.R_LIBS_USER }}
53+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
54+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
55+
56+
- name: Install system dependencies
57+
if: runner.os == 'Linux'
58+
run: |
59+
while read -r cmd
60+
do
61+
eval sudo $cmd
62+
done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")')
63+
64+
- name: Install dependencies
65+
run: |
66+
remotes::install_deps(dependencies = TRUE)
67+
remotes::install_cran("rcmdcheck")
68+
shell: Rscript {0}
69+
70+
- name: Check
71+
env:
72+
_R_CHECK_CRAN_INCOMING_REMOTE_: false
73+
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
74+
shell: Rscript {0}
75+
76+
- name: Upload check results
77+
if: failure()
78+
uses: actions/upload-artifact@main
79+
with:
80+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
81+
path: check

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
2+
3+
language: R
4+
cache: packages
5+
6+
r:
7+
- oldrel
8+
- release
9+
- devel
10+
11+
warnings_are_errors: true

DESCRIPTION

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: codecheck
2-
Title: Helper Functions for CODECHECK project
3-
Version: 0.0.0.9005
2+
Title: Helper Functions for CODECHECK Project
3+
Version: 0.0.0.9010
44
Authors@R:
55
c(person(given = "Stephen",
66
family = "Eglen",
@@ -12,12 +12,25 @@ Authors@R:
1212
role = c("aut"),
1313
email = "[email protected]",
1414
comment = c(ORCID = "0000-0002-0024-5046")))
15-
Description: This contains helper functions for CODECHECKERS (https://codecheck.org.uk).
15+
Description: This contains helper functions for CODECHECKERS (<https://codecheck.org.uk>).
1616
License: MIT + file LICENSE
17-
Depends: gh, R.cache, parsedate
18-
Imports: yaml, xtable, stringr, rmarkdown, knitr, jsonlite, assertthat
17+
Depends: R (>= 4.0.0), gh, R.cache, parsedate
18+
Imports:
19+
yaml,
20+
xtable,
21+
stringr,
22+
rmarkdown,
23+
knitr,
24+
jsonlite,
25+
assertthat,
26+
rorcid,
27+
osfr
1928
Encoding: UTF-8
2029
LazyData: true
21-
RoxygenNote: 7.1.0
30+
RoxygenNote: 7.1.1
2231
Remotes: eblondel/zen4R
2332
VignetteBuilder: knitr
33+
Suggests:
34+
tinytest,
35+
ttdo,
36+
skimr

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export(get_zenodo_record)
1010
export(latex_codecheck_logo)
1111
export(latex_summary_of_manifest)
1212
export(latex_summary_of_metadata)
13+
export(list_manifest_files)
1314
export(register_check)
1415
export(register_clear_cache)
1516
export(register_render)
@@ -20,8 +21,12 @@ importFrom(R.cache,addMemoization)
2021
importFrom(R.cache,getCacheRootPath)
2122
importFrom(gh,gh)
2223
importFrom(knitr,kable)
24+
importFrom(osfr,osf_download)
25+
importFrom(osfr,osf_ls_files)
26+
importFrom(osfr,osf_retrieve_node)
2327
importFrom(parsedate,parse_date)
2428
importFrom(rmarkdown,render)
29+
importFrom(rorcid,check_dois)
2530
importFrom(stringr,str_match)
2631
importFrom(stringr,str_replace_all)
2732
importFrom(utils,capture.output)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# codecheck 0.0.0.90xx
2+
3+
* Added tests using `tinytest`
4+
* Added a `NEWS.md` file to track changes to the package.

R/codecheck.R

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,43 @@
1010
##' @export
1111
create_codecheck_files <- function() {
1212
if (file.exists("codecheck.yml"))
13-
stop("codecheck.yml already exists, so stopping.")
14-
else
13+
warning("codecheck.yml already exists, so not overwriting it.",
14+
"See the template file at ",
15+
system.file("extdata", "templates/codecheck.yml", package="codecheck"),
16+
" for required metadata and examples.")
17+
else
18+
copy_codecheck_yaml_template()
19+
1520
if (dir.exists("codecheck"))
1621
stop("codecheck folder exists, so stopping.")
17-
copy_codecheck_yaml_template()
18-
copy_codecheck_report_template()
22+
else
23+
copy_codecheck_report_template()
1924
}
2025

2126
copy_codecheck_yaml_template <- function(target = ".") {
2227
templates <- system.file("extdata", "templates", package="codecheck")
2328
file.copy(file.path(templates, "codecheck.yml"), target)
29+
cat("Created codecheck.yml file at ", target, "\n")
2430
}
2531

2632
copy_codecheck_report_template <- function(target = ".") {
2733
templates <- system.file("extdata", "templates", package="codecheck")
2834
file.copy(file.path(templates, "codecheck"), target, recursive = TRUE)
35+
cat("Created codecheck report files at ", target, ":", toString(list.files("codecheck")), "\n")
2936
}
3037

31-
32-
3338
##' Return the metadata for the codecheck project in root folder of project
3439
##'
3540
##' @title Return the metadata for the codecheck project in root folder of project
36-
##' @param root Path to the root folder of the project.
41+
##' @param root Path to the root folder of the project, defaults to current working directory
3742
##' @return A list containing the metadata found in the codecheck.yml file
3843
##' @author Stephen Eglen
3944
##' @importFrom yaml read_yaml
4045
##' @export
41-
codecheck_metadata <- function(root) {
42-
read_yaml( file.path(root, "codecheck.yml") )
46+
codecheck_metadata <- function(root = getwd()) {
47+
read_yaml(file.path(root, "codecheck.yml") )
4348
}
4449

45-
4650
##' Copy manifest files into the root/codecheck/outputs folder; return manifest.
4751
##'
4852
##' The metadata should specify the manifest -- the files to copy into the
@@ -51,17 +55,19 @@ codecheck_metadata <- function(root) {
5155
##' If KEEP_FULL_PATH is TRUE, we keep the full path for the output files.
5256
##' This is useful when there are two output files with the same name in
5357
##' different folders, e.g. expt1/out.pdf and expt2/out.pdf
54-
58+
##'
5559
##' @title Copy files from manifest into the codecheck folder and summarise.
56-
##' @param root - Path to the root folder of the proejct.
60+
##' @param root - Path to the root folder of the project.
5761
##' @param metadata - the codecheck metadata list.
5862
##' @param dest_dir - folder where outputs are to be copied to (codecheck/outputs)
5963
##' @param keep_full_path - TRUE to keep relative pathname of figures.
64+
##' @param overwrite - TRUE to overwrite the output files even if they already exist
6065
##' @return A dataframe containing one row per manifest file.
6166
##' @author Stephen Eglen
6267
##' @export
6368
copy_manifest_files <- function(root, metadata, dest_dir,
64-
keep_full_path = FALSE) {
69+
keep_full_path = FALSE,
70+
overwrite = FALSE) {
6571
manifest = metadata$manifest
6672
outputs = sapply(manifest, function(x) x$file)
6773
src_files = file.path(root, outputs)
@@ -83,8 +89,10 @@ copy_manifest_files <- function(root, metadata, dest_dir,
8389
dir.create(dir, recursive=TRUE)
8490
}
8591
}
86-
file.copy(src_files, dest_files, overwrite=TRUE)
87-
dest_files
92+
93+
if (overwrite) message("Overwriting output files: ", toString(dest_files))
94+
file.copy(src_files, dest_files, overwrite = overwrite)
95+
8896
manifest_df = data.frame(output=outputs,
8997
comment=sapply(manifest, function(x) x$comment),
9098
dest=dest_files,
@@ -93,11 +101,29 @@ copy_manifest_files <- function(root, metadata, dest_dir,
93101
manifest_df
94102
}
95103

96-
97-
104+
##' List manifest.
105+
##'
106+
##' @title Summarise manifest files.
107+
##' @param root - Path to the root folder of the project.
108+
##' @param metadata - the codecheck metadata list.
109+
##' @param check_dir - folder where outputs have been copied to (codecheck/outputs)
110+
##' @return A dataframe containing one row per manifest file.
111+
##' @author Daniel Nüst
112+
##' @export
113+
list_manifest_files <- function(root, metadata, check_dir) {
114+
manifest = metadata$manifest
115+
outputs = sapply(manifest, function(x) x$file)
116+
dest_files = file.path(check_dir, basename(outputs))
117+
manifest_df = data.frame(output=outputs,
118+
comment=sapply(manifest, function(x) x$comment),
119+
dest=dest_files,
120+
size=file.size(dest_files),
121+
stringsAsFactors = FALSE)
122+
manifest_df
123+
}
98124

99125
## latex summary of metadata
100-
126+
##
101127
## https://daringfireball.net/2010/07/improved_regex_for_matching_urls
102128
## To use the URL in R, I had to escape the \ characters and " -- this version
103129
## does not work:
@@ -117,7 +143,7 @@ copy_manifest_files <- function(root, metadata, dest_dir,
117143
##' Wrap URL for LaTeX
118144
##'
119145
##' @param x - A string that may contain URLs that should be hyperlinked.
120-
##' @return A string with the passed url as a latex `\url{}`
146+
##' @return A string with the passed URL as a latex `\url{http://the.url}`
121147
##' @author Stephen Eglen
122148
##' @importFrom stringr str_replace_all
123149
as_latex_url <- function(x) {
@@ -265,7 +291,7 @@ create_zenodo_record <- function(zen) {
265291
this_doi = myrec$metadata$prereserve_doi$doi
266292
cat("The following URL is your Zenodo DOI.\n")
267293
cat("Please add this to codecheck.yml in report: field\n")
268-
print(this_doi)
294+
print(paste0("https://doi.org/", this_doi))
269295
cat("Remember to reload the yaml file after editing it.\n")
270296
get_zenodo_record(this_doi)
271297
}

0 commit comments

Comments
 (0)