Skip to content

Commit 3c95a83

Browse files
committed
Fix a few problems in R code found by check()
Most notably, latex_summary_of_manifest() has new first arg, the metadata.
1 parent e5be805 commit 3c95a83

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

R/codecheck.R

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ copy_codecheck_report_template <- function(target = ".") {
3636
##' @param root Path to the root folder of the project.
3737
##' @return A list containing the metadata found in the codecheck.yml file
3838
##' @author Stephen Eglen
39+
##' @importFrom yaml read_yaml
3940
##' @export
4041
codecheck_metadata <- function(root) {
4142
read_yaml( file.path(root, "codecheck.yml") )
@@ -61,6 +62,7 @@ codecheck_metadata <- function(root) {
6162
##' @export
6263
copy_manifest_files <- function(root, metadata, dest_dir,
6364
keep_full_path = FALSE) {
65+
manifest = metadata$manifest
6466
outputs = sapply(manifest, function(x) x$file)
6567
src_files = file.path(root, outputs)
6668
missing = !file.exists(src_files)
@@ -99,15 +101,25 @@ copy_manifest_files <- function(root, metadata, dest_dir,
99101
## https://daringfireball.net/2010/07/improved_regex_for_matching_urls
100102
## To use the URL in R, I had to escape the \ characters and " -- this version
101103
## does not work:
102-
## .url_regexp = "(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))"
104+
## .url_regexp = "(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?...]))"
103105

104-
.url_regexp = "(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))"
106+
## Have also converted the unicode into \uxxxx escapes to keep
107+
## devtools::check() happy
108+
## « -> \u00ab
109+
## » -> \u00bb
110+
## “ -> \u201c
111+
## ” -> \u201d
112+
## ‘ -> \u2018
113+
## ’ -> \u2019
114+
115+
.url_regexp = "(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))"
105116

106117
##' Wrap URL for LaTeX
107118
##'
108-
##' @param url - TRUE to keep relative pathname of figures.
119+
##' @param x - A string that may contain URLs that should be hyperlinked.
109120
##' @return A string with the passed url as a latex `\url{}`
110121
##' @author Stephen Eglen
122+
##' @importFrom stringr str_replace_all
111123
as_latex_url <- function(x) {
112124
wrapit <- function(url) { paste0("\\url{", url, "}") }
113125
str_replace_all(x, .url_regexp, wrapit)
@@ -147,6 +159,7 @@ as_latex_url <- function(x) {
147159
##' @param metadata - the codecheck metadata list.
148160
##' @return The latex table, suitable for including in the Rmd
149161
##' @author Stephen Eglen
162+
##' @importFrom xtable xtable
150163
##' @export
151164
latex_summary_of_metadata <- function(metadata) {
152165
summary_entries = list(
@@ -172,13 +185,15 @@ latex_summary_of_metadata <- function(metadata) {
172185
##'
173186
##' Format a latex table that summarises the main CODECHECK manifest
174187
##' @title Print a latex table to summarise CODECHECK metadata
188+
##' @param metadata - the codecheck metadata list.
175189
##' @param manifest_df - The manifest data frame
176190
##' @param root - root directory of the project
177191
##' @param align - alignment flags for the table.
178192
##' @return The latex table, suitable for including in the Rmd
179193
##' @author Stephen Eglen
194+
##' @importFrom xtable xtable
180195
##' @export
181-
latex_summary_of_manifest <- function(manifest_df,
196+
latex_summary_of_manifest <- function(metadata, manifest_df,
182197
root,
183198
align=c('l', 'p{6cm}', 'p{6cm}', 'p{2cm}')
184199
) {
@@ -243,9 +258,10 @@ citation <- function(metadata) {
243258
##' @param zen - Object from zen4R to interact with Zenodo
244259
##' @return Number of zenodo record created.
245260
##' @author Stephen Eglen
261+
##'
246262
##' @export
247263
create_zenodo_record <- function(zen) {
248-
myrec <- zenodo$createEmptyRecord()
264+
myrec <- zen$createEmptyRecord()
249265
this_doi = myrec$metadata$prereserve_doi$doi
250266
cat("The following URL is your Zenodo DOI.\n")
251267
cat("Please add this to codecheck.yml in report: field\n")
@@ -268,6 +284,7 @@ create_zenodo_record <- function(zen) {
268284
##' @param report - string containing the report URL on Zenodo.
269285
##' @return the Zenodo record number (a number with at least 7 digits).
270286
##' @author Stephen Eglen
287+
##' @importFrom stringr str_match
271288
##' @export
272289
get_zenodo_record <- function(report) {
273290
result = str_match(report, "10\\.5281/zenodo\\.([0-9]{7,})")[2]

0 commit comments

Comments
 (0)