Skip to content
Snippets Groups Projects
Commit 2d73101f authored by Dorch's avatar Dorch
Browse files

fix: error in create_reports

- correction of reports/.gitignore file creation
- resolve check issues

Refs #3
parent bf0df3ef
No related branches found
No related tags found
No related merge requests found
Pipeline #121178 failed
Showing
with 105 additions and 34 deletions
......@@ -9,6 +9,7 @@ export(getDataPath)
export(iconv_filename)
export(loadConfig)
export(pkg_sys)
export(purge_string)
export(render_report)
export(render_reports)
export(updateMermaid)
......
#' Add .gitignore file suitable for R project
#'
#' @inheritParams create_fairify
#' @inheritParams utils::download.file
#' @param url URL of a `.gitignore` template file
#' @param additional_patterns Patterns to add to the `.gitignore` file
#'
#' @return `NULL`, this function is used for side effect.
#' @export
......@@ -12,16 +13,16 @@
#' readLines(file.path(path, ".gitignore"))
add_gitignore <- function(path = ".",
url = "https://raw.githubusercontent.com/github/gitignore/main/R.gitignore",
additional_paths = c("/public")) {
additional_patterns = c("/public")) {
destfile = file.path(path, ".gitignore")
stopifnot(download.file(url, destfile) == 0)
s <- readLines(destfile)
s <- c(add_comment_block("R template from:",
s <- c(add_comment_block(".gitignore template from:",
url,
paste("Downloaded the", Sys.time())),
s,
add_comment_block("Specific files for fairify"),
additional_paths)
additional_patterns)
writeLines(s, destfile)
}
......
......@@ -12,7 +12,7 @@
#' @export
#'
#' @examples
#' path <- tempdir()
#' path <- tempfile(pattern = "dir")
#' create_fairify(path, open = FALSE)
#' list.files(path)
create_fairify <-
......
......@@ -3,12 +3,13 @@
#' @param path Destination folder for reports and templates
#' @param overwrite Allow overwriting templates folder
#'
#' @return Use for side effect.
#' @return The path to the created reports folder.
#' @export
#'
#' @examples
#' # Create structure for reports
#' path <- tempdir()
#' path <- tempfile(pattern = "dir")
#' dir.create(path)
#' create_reports(path)
#' list.files(path, recursive = TRUE)
#'
......@@ -24,15 +25,19 @@ create_reports <- function(path = ".", overwrite = FALSE) {
stop("Folder ", file.path(path, "templates"), " already exists")
}
}
file.copy(from = pkg_sys("templates"),
to = path,
recursive = TRUE,
copy.date = TRUE)
ok <- file.copy(
from = pkg_sys("templates"),
to = path,
recursive = TRUE
)
if (!ok) stop("Error when copying 'templates' folder to ", path)
# Create reports folder
file.copy(from = pkg_sys("reports"),
to = path,
recursive = TRUE,
copy.date = TRUE)
invisible()
reports_path <- file.path(path, "reports")
dir.create(reports_path)
add_gitignore(reports_path,
url = "https://raw.githubusercontent.com/github/gitignore/main/TeX.gitignore",
additional_patterns = readLines(pkg_sys("reports_gitignore.txt")))
invisible(file.path(path, "reports"))
}
......@@ -39,5 +39,5 @@ render_report <- function(input,
function(x) detach(paste0("package:", x),
unload = TRUE,
character.only = TRUE))
NULL
invisible()
}
......@@ -15,7 +15,7 @@
#'
#' @examples
render_reports <- function(reports_dir = "./reports",
reports = list.dirs(reports_dir),
reports = list.dirs(reports_dir, full.names = FALSE, recursive = FALSE),
publish_dir = "../../public/reports",
...) {
......@@ -28,10 +28,9 @@ render_reports <- function(reports_dir = "./reports",
message("*******************************************************************")
message("** RENDER ", report)
message("*******************************************************************")
path <-
render_report(input = file.path(reports_dir, report),
output_dir = file.path(publish_dir, report),
...)
}
NULL
invisible()
}
......@@ -20,3 +20,24 @@ pkg_sys <- function(
mustWork = mustWork
)
}
#' Purge a string from all accents and special characters
#'
#' @param x the [character] string to purge
#' @param replacement the [character] to use for replacing special characters
#'
#' @return A purged [character] string
#' @export
#'
#' @examples
#' purge_string("Là chaîne pl€ine dé &#/* $péciaux", "_")
#'
purge_string <- function(x, replacement = " ") {
iconv(gsub(paste0(replacement, "+"), replacement,
gsub("&|=|-|:|\\.|'|\\/|<|>|e0|e9|e8|e7|e6|_|\\(|\\)|\"|\\*|#|€|\\$|\\%",
replacement,
enc2utf8(x))),
from = "UTF-8",
to = "ASCII//TRANSLIT")
}
book_filename: "_01-GRS_specs"
book_filename: "report"
delete_merged_file: true
language:
ui:
......
File moved
......@@ -26,7 +26,8 @@
% http://tex.stackexchange.com/a/13691/124910
% \usepackage{tocstyle} % tocstyle is deprecated see https://ctan.org/pkg/tocstyle
\usepackage{tocbasic}
\usepackage{scrwfile}
% In case of `no room for new \write` issue
% \usepackage{scrwfile}
% Ajout de la gestion des couleurs
% The \usepackage is obvious, but the initialization of additional commands like usenames allows you to use names of the default colors, the same 16 base colors as used in HTML. The dvipsnames allows you access to more colors, another 64, and svgnames allows access to about 150 colors. The initialization of "table" allows colors to be added to tables by placing the color command just before the table. https://en.wikibooks.org/wiki/LaTeX/Colors
......
......@@ -7,16 +7,16 @@
add_gitignore(
path = ".",
url = "https://raw.githubusercontent.com/github/gitignore/main/R.gitignore",
additional_paths = c("/public")
additional_patterns = c("/public")
)
}
\arguments{
\item{path}{A path. If it exists, it is used. If it does not exist, it is
created, provided that the parent path exists.}
\item{url}{a \code{\link{character}} string (or longer vector
for the \code{"libcurl"} method) naming the URL of a resource to be
downloaded.}
\item{url}{URL of a \code{.gitignore} template file}
\item{additional_patterns}{Patterns to add to the \code{.gitignore} file}
}
\value{
\code{NULL}, this function is used for side effect.
......
......@@ -19,7 +19,8 @@ Add a new report in a fairify project
}
\examples{
# Create structure for reports
path <- tempdir()
path <- tempfile(pattern = "dir")
dir.create(path)
create_reports(path)
list.files(path, recursive = TRUE)
......
......@@ -43,7 +43,7 @@ Use for side effect.
Create a package ready for fairify your project.
}
\examples{
path <- tempdir()
path <- tempfile(pattern = "dir")
create_fairify(path, open = FALSE)
list.files(path)
}
......@@ -12,14 +12,15 @@ create_reports(path = ".", overwrite = FALSE)
\item{overwrite}{Allow overwriting templates folder}
}
\value{
Use for side effect.
The path to the created reports folder.
}
\description{
Set reports folder structure
}
\examples{
# Create structure for reports
path <- tempdir()
path <- tempfile(pattern = "dir")
dir.create(path)
create_reports(path)
list.files(path, recursive = TRUE)
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{purge_string}
\alias{purge_string}
\title{Purge a string from all accents and special characters}
\usage{
purge_string(x, replacement = " ")
}
\arguments{
\item{x}{the \link{character} string to purge}
\item{replacement}{the \link{character} to use for replacing special characters}
}
\value{
A purged \link{character} string
}
\description{
Purge a string from all accents and special characters
}
\examples{
purge_string("Là chaîne pl€ine dé &#/* $péciaux", "_")
}
......@@ -15,7 +15,7 @@ render_report(
render_reports(
reports_dir = "./reports",
reports = list.dirs(reports_dir),
reports = list.dirs(reports_dir, full.names = FALSE, recursive = FALSE),
publish_dir = "../../public/reports",
...
)
......
......@@ -6,7 +6,7 @@ test_that("create_fairify works", {
expect_true(file.exists(file.path(path, ".git")))
})
test_that("create_fairify with git = FALSE doesn't create git repoworks", {
test_that("create_fairify with git = FALSE doesn't create git repo works", {
path <- tempfile(pattern = "dir")
create_fairify(path, open = FALSE, git = FALSE)
project <- basename(path)
......
test_that("create_reports works", {
path <- tempdir()
create_reports(path)
path <- tempfile(pattern = "dir")
dir.create(path, recursive = TRUE)
expect_equal(create_reports(path),
file.path(path, "reports"))
expect_true(all(dir.exists(file.path(path, c("reports", "templates")))))
expect_error(create_reports(path))
expect_warning(create_reports(path, overwrite = TRUE))
})
skip_on_ci()
test_that("render_reports works", {
path <- tempfile(pattern = "dir")
create_fairify(path, open = FALSE)
add_report("my_report", path)
render_reports(reports_dir = file.path(path, "reports"),
output_format = "bookdown::gitbook")
report_path <- file.path(path, "public/reports/my_report")
expect_true(dir.exists(report_path))
expect_true(file.exists(file.path(report_path, "index.html")))
render_reports(reports_dir = file.path(path, "reports"),
output_format = "bookdown::pdf_book")
expect_true(file.exists())
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment