10
10
# #' @export
11
11
create_codecheck_files <- function () {
12
12
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
+
15
20
if (dir.exists(" codecheck" ))
16
21
stop(" codecheck folder exists, so stopping." )
17
- copy_codecheck_yaml_template()
18
- copy_codecheck_report_template()
22
+ else
23
+ copy_codecheck_report_template()
19
24
}
20
25
21
26
copy_codecheck_yaml_template <- function (target = " ." ) {
22
27
templates <- system.file(" extdata" , " templates" , package = " codecheck" )
23
28
file.copy(file.path(templates , " codecheck.yml" ), target )
29
+ cat(" Created codecheck.yml file at " , target , " \n " )
24
30
}
25
31
26
32
copy_codecheck_report_template <- function (target = " ." ) {
27
33
templates <- system.file(" extdata" , " templates" , package = " codecheck" )
28
34
file.copy(file.path(templates , " codecheck" ), target , recursive = TRUE )
35
+ cat(" Created codecheck report files at " , target , " :" , toString(list.files(" codecheck" )), " \n " )
29
36
}
30
37
31
-
32
-
33
38
# #' Return the metadata for the codecheck project in root folder of project
34
39
# #'
35
40
# #' @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
37
42
# #' @return A list containing the metadata found in the codecheck.yml file
38
43
# #' @author Stephen Eglen
39
44
# #' @importFrom yaml read_yaml
40
45
# #' @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" ) )
43
48
}
44
49
45
-
46
50
# #' Copy manifest files into the root/codecheck/outputs folder; return manifest.
47
51
# #'
48
52
# #' The metadata should specify the manifest -- the files to copy into the
@@ -51,17 +55,19 @@ codecheck_metadata <- function(root) {
51
55
# #' If KEEP_FULL_PATH is TRUE, we keep the full path for the output files.
52
56
# #' This is useful when there are two output files with the same name in
53
57
# #' different folders, e.g. expt1/out.pdf and expt2/out.pdf
54
-
58
+ # #'
55
59
# #' @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 .
57
61
# #' @param metadata - the codecheck metadata list.
58
62
# #' @param dest_dir - folder where outputs are to be copied to (codecheck/outputs)
59
63
# #' @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
60
65
# #' @return A dataframe containing one row per manifest file.
61
66
# #' @author Stephen Eglen
62
67
# #' @export
63
68
copy_manifest_files <- function (root , metadata , dest_dir ,
64
- keep_full_path = FALSE ) {
69
+ keep_full_path = FALSE ,
70
+ overwrite = FALSE ) {
65
71
manifest = metadata $ manifest
66
72
outputs = sapply(manifest , function (x ) x $ file )
67
73
src_files = file.path(root , outputs )
@@ -83,8 +89,10 @@ copy_manifest_files <- function(root, metadata, dest_dir,
83
89
dir.create(dir , recursive = TRUE )
84
90
}
85
91
}
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
+
88
96
manifest_df = data.frame (output = outputs ,
89
97
comment = sapply(manifest , function (x ) x $ comment ),
90
98
dest = dest_files ,
@@ -93,11 +101,29 @@ copy_manifest_files <- function(root, metadata, dest_dir,
93
101
manifest_df
94
102
}
95
103
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
+ }
98
124
99
125
# # latex summary of metadata
100
-
126
+ # #
101
127
# # https://daringfireball.net/2010/07/improved_regex_for_matching_urls
102
128
# # To use the URL in R, I had to escape the \ characters and " -- this version
103
129
# # does not work:
@@ -117,7 +143,7 @@ copy_manifest_files <- function(root, metadata, dest_dir,
117
143
# #' Wrap URL for LaTeX
118
144
# #'
119
145
# #' @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 }`
121
147
# #' @author Stephen Eglen
122
148
# #' @importFrom stringr str_replace_all
123
149
as_latex_url <- function (x ) {
@@ -265,7 +291,7 @@ create_zenodo_record <- function(zen) {
265
291
this_doi = myrec $ metadata $ prereserve_doi $ doi
266
292
cat(" The following URL is your Zenodo DOI.\n " )
267
293
cat(" Please add this to codecheck.yml in report: field\n " )
268
- print(this_doi )
294
+ print(paste0( " https://doi.org/ " , this_doi ) )
269
295
cat(" Remember to reload the yaml file after editing it.\n " )
270
296
get_zenodo_record(this_doi )
271
297
}
0 commit comments