|
25 | 25 | #' pr |
26 | 26 | #' file.remove(pr) |
27 | 27 | package_report <- function( |
28 | | - package_name, |
29 | | - package_version, |
30 | | - package = NULL, |
31 | | - template_path = system.file("report/package", package = "val.report"), |
32 | | - output_format = "all", |
33 | | - params = list(), |
34 | | - ... |
| 28 | + package_name, |
| 29 | + package_version, |
| 30 | + package = NULL, |
| 31 | + template_path = system.file("report/package", package = "val.report"), |
| 32 | + output_format = "all", |
| 33 | + params = list(), |
| 34 | + ... |
35 | 35 | ) { |
36 | | - empty_pkg_info <- is.empty(package_name) && is.empty(package_version) |
37 | | - if (empty_pkg_info && !is.empty(package)) { |
38 | | - package_name <- basename(package) |
39 | | - desc <- read.dcf(file.path(package, "DESCRIPTION")) |
40 | | - |
41 | | - stopifnot("Mismatch between path and DESCRIPTION name" = package_name == desc[, "Package"]) |
42 | | - package_version <- desc[, "Version"] |
43 | | - params$package <- package |
44 | | - Sys.setenv("INPUT_REPORT_PKG_DIR" = package) |
45 | | - } else if (empty_pkg_info && is.empty(package)) { |
46 | | - stop("Package information missing for the report") |
47 | | - } else { |
48 | | - params$package <- package_name |
49 | | - } |
50 | | - |
51 | | - full_name <- paste0(package_name, "_v", package_version) |
52 | | - output_file <- paste0("validation_report_", full_name, ".qmd") |
53 | | - |
54 | | - params$package_name <- package_name |
55 | | - params$package_version <- package_version |
56 | | - params$image <- get_image_name(params) |
57 | | - |
58 | | - if (is.null(template_path) || !nzchar(template_path)) { |
59 | | - template_path <- system.file("report/package", |
60 | | - package = "val.report") |
61 | | - } else if (!dir.exists(template_path)) { |
62 | | - stop("Template directory is not available") |
63 | | - } |
64 | | - |
65 | | - params$package <- normalizePath(params$package, mustWork = FALSE, winslash = "/") |
66 | | - if (length(params$assessment_path) == 1L && !nzchar(params$assessment_path)) { |
67 | | - params$assessment_path <- normalizePath(params$assessment_path, mustWork = TRUE, winslash = "/") |
68 | | - } |
69 | | - |
70 | | - # Bug on https://github.com/quarto-dev/quarto-cli/issues/5765 |
71 | | - v <- quarto::quarto_version() |
72 | | - if (v < package_version("1.7.13")) { |
73 | | - warning("Please install the latest (devel) version of Quarto") |
74 | | - } |
75 | | - |
76 | | - if (is.null(params$source)) warning("Please provide the source of the package assessment") |
77 | | - |
78 | | - # https://github.com/quarto-dev/quarto-r/issues/81#issuecomment-1375691267 |
79 | | - # quarto rendering happens in the same place as the file/project |
80 | | - # To avoid issues copy to a different place and render there. |
81 | | - render_dir <- output_dir() |
| 36 | + empty_pkg_info <- is.empty(package_name) && is.empty(package_version) |
| 37 | + if (empty_pkg_info && !is.empty(package)) { |
| 38 | + package_name <- basename(package) |
| 39 | + desc <- read.dcf(file.path(package, "DESCRIPTION")) |
| 40 | + |
| 41 | + stopifnot( |
| 42 | + "Mismatch between path and DESCRIPTION name" = package_name == |
| 43 | + desc[, "Package"] |
| 44 | + ) |
| 45 | + package_version <- desc[, "Version"] |
| 46 | + params$package <- package |
| 47 | + Sys.setenv("INPUT_REPORT_PKG_DIR" = package) |
| 48 | + } else if (empty_pkg_info && is.empty(package)) { |
| 49 | + stop("Package information missing for the report") |
| 50 | + } else { |
| 51 | + params$package <- package_name |
| 52 | + } |
| 53 | + |
| 54 | + full_name <- paste0(package_name, "_v", package_version) |
| 55 | + output_file <- paste0("validation_report_", full_name, ".qmd") |
| 56 | + |
| 57 | + params$package_name <- package_name |
| 58 | + params$package_version <- package_version |
| 59 | + params$image <- get_image_name(params) |
| 60 | + |
| 61 | + if (is.null(template_path) || !nzchar(template_path)) { |
| 62 | + template_path <- system.file("report/package", package = "val.report") |
| 63 | + } else if (!dir.exists(template_path)) { |
| 64 | + stop("Template directory is not available") |
| 65 | + } |
| 66 | + |
| 67 | + params$package <- normalizePath( |
| 68 | + params$package, |
| 69 | + mustWork = FALSE, |
| 70 | + winslash = "/" |
| 71 | + ) |
| 72 | + if (length(params$assessment_path) == 1L && !nzchar(params$assessment_path)) { |
| 73 | + params$assessment_path <- normalizePath( |
| 74 | + params$assessment_path, |
| 75 | + mustWork = TRUE, |
| 76 | + winslash = "/" |
| 77 | + ) |
| 78 | + } |
| 79 | + |
| 80 | + # Bug on https://github.com/quarto-dev/quarto-cli/issues/5765 |
| 81 | + v <- quarto::quarto_version() |
| 82 | + if (v < package_version("1.7.13")) { |
| 83 | + warning("Please install the latest (devel) version of Quarto") |
| 84 | + } |
| 85 | + |
| 86 | + if (is.null(params$source)) { |
| 87 | + warning("Please provide the source of the package assessment") |
| 88 | + } |
| 89 | + |
| 90 | + # https://github.com/quarto-dev/quarto-r/issues/81#issuecomment-1375691267 |
| 91 | + # quarto rendering happens in the same place as the file/project |
| 92 | + # To avoid issues copy to a different place and render there. |
| 93 | + render_dir <- output_dir() |
| 94 | + if (!dir.exists(render_dir)) { |
| 95 | + render_dir <- paste0(render_dir, "/") |
82 | 96 | if (!dir.exists(render_dir)) { |
83 | | - render_dir <- paste0(render_dir, "/") |
84 | | - if (!dir.exists(render_dir)) { |
85 | | - stop("Render directory doesn't exists. Please check the 'getOptions(\"valreport_output_dir\")' and sys.getEnv(\"VALREPORT_OUTPUT_DIR\")" ) |
86 | | - } |
87 | | - } |
88 | | - files_to_copy <- list.files(template_path, full.names = TRUE) |
89 | | - fc <- file.copy(from = files_to_copy, |
90 | | - to = render_dir, |
91 | | - overwrite = TRUE, |
92 | | - copy.date = TRUE) |
93 | | - |
94 | | - if (any(!fc)) { |
95 | | - stop("Copying to the rendering directory failed.") |
96 | | - } |
97 | | - |
98 | | - template_all_files <- list.files(render_dir, full.names = TRUE) |
99 | | - template <- template_all_files[endsWith(template_all_files, "qmd")] |
100 | | - |
101 | | - if (length(template) > 1) { |
102 | | - stop("There are more than one template!\n", |
103 | | - "Please have only one quarto file on the directory.") |
| 97 | + stop( |
| 98 | + "Render directory doesn't exists. Please check the 'getOptions(\"valreport_output_dir\")' and sys.getEnv(\"VALREPORT_OUTPUT_DIR\")" |
| 99 | + ) |
104 | 100 | } |
| 101 | + } |
| 102 | + files_to_copy <- list.files(template_path, full.names = TRUE) |
| 103 | + fc <- file.copy( |
| 104 | + from = files_to_copy, |
| 105 | + to = render_dir, |
| 106 | + overwrite = TRUE, |
| 107 | + copy.date = TRUE |
| 108 | + ) |
| 109 | + |
| 110 | + if (any(!fc)) { |
| 111 | + stop("Copying to the rendering directory failed.") |
| 112 | + } |
| 113 | + |
| 114 | + template_all_files <- list.files(render_dir, full.names = TRUE) |
| 115 | + template <- template_all_files[endsWith(template_all_files, "qmd")] |
| 116 | + |
| 117 | + if (length(template) > 1) { |
| 118 | + stop( |
| 119 | + "There are more than one template!\n", |
| 120 | + "Please have only one quarto file on the directory." |
| 121 | + ) |
| 122 | + } |
| 123 | + |
| 124 | + file_template <- file.path( |
| 125 | + render_dir, |
| 126 | + paste0("validation_report_", full_name, ".qmd") |
| 127 | + ) |
| 128 | + file.rename(template, file_template) |
| 129 | + |
| 130 | + # replace the title of the place header by the package name and header |
| 131 | + top_page_file <- readLines(file.path(render_dir, "top_page.html")) |
| 132 | + title_line <- grep("<p", top_page_file) |
| 133 | + top_page_file[title_line] <- htmltools::p(paste0( |
| 134 | + "Validation Report - ", |
| 135 | + package_name, |
| 136 | + "@", |
| 137 | + package_version |
| 138 | + )) |> |
| 139 | + as.character() |
| 140 | + writeLines(top_page_file, file.path(render_dir, "top_page.html")) |
105 | 141 |
|
106 | | - file_template <- file.path(render_dir, |
107 | | - paste0("validation_report_", full_name, ".qmd")) |
108 | | - file.rename(template, file_template) |
109 | | - |
110 | | - # replace the title of the place header by the package name and header |
111 | | - top_page_file <- readLines(file.path(render_dir, "top_page.html")) |
112 | | - title_line <- grep("<p", top_page_file) |
113 | | - top_page_file[title_line] <- htmltools::p(paste0("Validation Report - ", package_name, "@", package_version)) |> |
114 | | - as.character() |
115 | | - writeLines(top_page_file, file.path(render_dir, "top_page.html")) |
116 | | - |
117 | | - pre_rendering <- list.files(render_dir, full.names = TRUE) |
| 142 | + pre_rendering <- list.files(render_dir, full.names = TRUE) |
118 | 143 |
|
119 | | - suppressMessages({suppressWarnings({ |
| 144 | + suppressMessages({ |
| 145 | + suppressWarnings({ |
120 | 146 | out <- quarto::quarto_render( |
121 | 147 | input = file_template, |
122 | 148 | output_format = output_format, |
123 | 149 | execute_params = params, |
124 | 150 | ... |
125 | 151 | ) |
126 | | - })}) |
| 152 | + }) |
| 153 | + }) |
127 | 154 |
|
128 | | - post_rendering <- list.files(render_dir, full.names = TRUE) |
| 155 | + post_rendering <- list.files(render_dir, full.names = TRUE) |
129 | 156 |
|
130 | | - files_to_remove <- intersect(pre_rendering, post_rendering) |
131 | | - fr <- file.remove(files_to_remove) |
132 | | - if (any(!fr)) { |
133 | | - warning("Failed to remove the quarto template used from the directory.") |
134 | | - } |
| 157 | + files_to_remove <- intersect(pre_rendering, post_rendering) |
| 158 | + fr <- file.remove(files_to_remove) |
| 159 | + if (any(!fr)) { |
| 160 | + warning("Failed to remove the quarto template used from the directory.") |
| 161 | + } |
135 | 162 |
|
136 | | - output_files <- setdiff(post_rendering, pre_rendering) |
137 | | - invisible(output_files) |
| 163 | + output_files <- setdiff(post_rendering, pre_rendering) |
| 164 | + invisible(output_files) |
138 | 165 | } |
139 | 166 |
|
140 | 167 | is.empty <- function(x) { |
|
0 commit comments