Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
clemasso committed Aug 21, 2024
2 parents 7cb03d3 + 577a5d6 commit 5e72a43
Show file tree
Hide file tree
Showing 51 changed files with 1,169 additions and 801 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ vignettes/*.pdf
Meta/
inst/doc/
doc/
/doc/
/Meta/

# OAuth2 token, see https:/hadley/httr/releases/tag/v0.3
.httr-oauth
Expand Down
4 changes: 3 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ linters: linters_with_defaults(
object_usage_linter = NULL,
object_name_linter = NULL,
line_length_linter = NULL,
commented_code_linter = NULL
commented_code_linter = NULL,
cyclocomp_linter = NULL,
brace_linter = NULL
)
encoding: "UTF-8"
24 changes: 14 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rjd3revisions
Type: Package
Title: Revision analysis with 'JDemetra+ 3.x'
Version: 1.3.2
Version: 1.4.0
Authors@R: c(
person(given = "Corentin", family = "Lemasson",
email = "[email protected]", role = c("aut", "cre")),
Expand All @@ -12,6 +12,10 @@ Description: Revision analysis tool part of 'JDemetra+ 3.x' (<https:
with the results. The various tests enable the users to detect
potential bias and sources of inefficiency in preliminary
estimates.
License: EUPL | file LICENSE
URL: https:/rjdverse/rjd3revisions, https://rjdverse.github.io/rjd3revisions/
BugReports: https:/rjdverse/rjd3revisions/issues
SystemRequirements: Java (>= 17)
Depends:
R (>= 4.1.0)
Imports:
Expand All @@ -22,32 +26,32 @@ Imports:
utils,
stats,
grDevices,
graphics
graphics,
methods
Suggests:
kableExtra,
testthat (>= 3.0.0),
knitr,
rmarkdown,
readxl,
formattable
flextable
Remotes:
github::rjdverse/rjd3toolkit@*release
SystemRequirements: Java (>= 17)
License: EUPL | file LICENSE
Encoding: UTF-8
github::rjdverse/rjd3toolkit
Collate:
'rjd3revisions-package.R'
'check.R'
'conversion.R'
'format_table.R'
'report.R'
'revisions.R'
'revision_analysis.R'
'simulate.R'
'tests.R'
'thresholds.R'
'vintages.R'
'zzz.R'
RoxygenNote: 7.3.2
URL: https:/rjdverse/rjd3revisions, https://rjdverse.github.io/rjd3revisions/
BugReports: https:/rjdverse/rjd3revisions/issues
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(View,default)
S3method(View,rjd3rev_rslts)
S3method(View,rjd3rev_vintages)
S3method(check_horizontal,data.frame)
S3method(check_horizontal,default)
Expand All @@ -20,6 +22,7 @@ S3method(print,rjd3rev_vintages)
S3method(summary,rjd3rev_revisions)
S3method(summary,rjd3rev_rslts)
S3method(summary,rjd3rev_vintages)
export(View)
export(bias)
export(check_date_month)
export(check_date_quarter)
Expand All @@ -40,7 +43,10 @@ export(orthogonallyModel1)
export(orthogonallyModel2)
export(render_report)
export(revision_analysis)
export(set_all_thresholds_to_default)
export(set_thresholds_to_default)
export(signalnoise)
export(simulate_long)
export(slope_and_drift)
export(theil)
export(theil2)
Expand All @@ -52,6 +58,8 @@ importFrom(grDevices,palette.colors)
importFrom(graphics,legend)
importFrom(graphics,par)
importFrom(graphics,title)
importFrom(methods,hasArg)
importFrom(stats,as.formula)
importFrom(stats,end)
importFrom(stats,frequency)
importFrom(stats,median)
Expand All @@ -60,6 +68,7 @@ importFrom(stats,quantile)
importFrom(stats,reshape)
importFrom(stats,rnorm)
importFrom(stats,start)
importFrom(stats,time)
importFrom(stats,ts)
importFrom(stats,ts.plot)
importFrom(tools,file_ext)
Expand Down
21 changes: 20 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]


## [1.4.0] - 2024-08-21

### Added

* user-defined thresholds for tests assessment
* possibility to add plot of revisions in report
* New `View()`, `summary()` and `print()` method to visualize the revision analysis

### Changed

* pivot from {formattable} dependency to {flextable} to build the tables
* `simulate_long()` is now an exported function to construct datasets example

### Fixed

* solve a display glitch in diagonal view of functions print.rjd3rev_vintages() and print.rjd3rev_revisions()


## [1.3.2] - 2024-07-10

### Added
Expand Down Expand Up @@ -92,7 +110,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

* Release based on JD+_main : v3.0.2

[Unreleased]: https:/rjdverse/rjd3revisions/compare/v1.3.2...HEAD
[Unreleased]: https:/rjdverse/rjd3revisions/compare/v1.4.0...HEAD
[1.4.0]: https:/rjdverse/rjd3revisions/releases/tag/v1.3.2...v1.4.0
[1.3.2]: https:/rjdverse/rjd3revisions/releases/tag/v1.3.1...v1.3.2
[1.3.1]: https:/rjdverse/rjd3revisions/releases/tag/v1.3.0...v1.3.1
[1.3.0]: https:/rjdverse/rjd3revisions/releases/tag/v1.2.1...v1.3.0
Expand Down
2 changes: 1 addition & 1 deletion R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ check_long <- function(x, date_format = "%Y-%m-%d") {
#' Check vertical format
#'
#' @param x a formatted \code{data.frame} containing the input in the vertical format
#' @param periodicity periodicity of the time period (12, 4 or 1 for resp.
#' @param periodicity Integer. Periodicity of the time period (12, 4 or 1 for resp.
#' monthly, quarterly or annual data)
#' @param date_format \code{character} string corresponding to the format used in
#' the input data.frame for the revision dates.
Expand Down
45 changes: 45 additions & 0 deletions R/format_table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
theme_design <- function(x) {
x <- flextable::border_remove(x)
std_border <- flextable::fp_border_default(width = 4, color = "white")
# x <- fontsize(x, size = 10, part = "all")
x <- flextable::font(x, fontname = "Helvetica Neue", part = "all")
x <- flextable::align(x, align = "center", part = "all")

x <- flextable::bg(x, bg = "gray94", part = "body")
x <- flextable::bg(x, bg = "gray74", part = "header")
x <- flextable::bg(x, bg = "#7ca2ff", part = "footer")
x <- flextable::color(x, color = "black", part = "all")

x <- flextable::bg(x, j = 1L, bg = "gray74")
x <- flextable::color(x, j = 1L, color = "black")

x <- flextable::padding(x, padding = 6, part = "all")
x <- flextable::border_outer(x, part = "all", border = std_border)
x <- flextable::border_inner_h(x, border = std_border, part = "all")
x <- flextable::border_inner_v(x, border = std_border, part = "all")
x <- flextable::set_table_properties(x, layout = "autofit")
return(x)
}

create_formula <- function(col, status) {
return(as.formula(sprintf("~ grepl(x = `%s`, pattern = \"%s\")", col, status)))
}

format_column <- function(x, col) {
x <- flextable::bg(x, create_formula(col, "Good"), col, bg = "#4CAF50")
x <- flextable::bg(x, create_formula(col, "Uncertain"), col, bg = "#FFEB3B")
x <- flextable::bg(x, create_formula(col, "Bad"), col, bg = "#ff3737")
x <- flextable::bg(x, create_formula(col, "Severe"), col, bg = "#c10000")
x <- flextable::bold(x, create_formula(col, "Severe"), col)
x <- flextable::color(x, create_formula(col, "Severe"), col, color = "white")
return(x)
}

format_table <- function(x, col = "Tests") {
formatted_table <- cbind(
data.frame(Tests = rownames(x)),
as.data.frame(x)
)
colnames(formatted_table)[1] <- col
return(formatted_table)
}
45 changes: 28 additions & 17 deletions R/report.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#' Generate report on Revision Analysis
#'
#' @param rslt an object of class `"rjd3rev_vintages"` which is the output
#' @param rslt an object of class `"rjd3rev_rslts"` which is the output
#' of the function `revision_analysis()`
#' @param output_file path or name of the output file containing the report
#' @param output_dir path of the dir containing the output file (Optional)
#' @param output_format either an HTML document (default) or a PDF document
#' @param output_format either an HTML document (default), a PDF document or a
#' Word document
#' @param plot_revisions Boolean. Default is FALSE meaning that a plot with the
#' revisions will not be added to the report.
#' @param open_report Boolean. Default is TRUE meaning that the report will
#' open automatically after being generated.
#' @param ... Arguments to be passed to `rmarkdown::render()`, for example:
Expand All @@ -18,33 +21,36 @@
#' @examples
#'
#' ## Simulated data
#'
#' long_format <- rjd3revisions:::simulate_long(
#' start_period = as.Date("2020-01-01"),
#' n_period = 24,
#' n_revision = 6,
#' periodicity = 12L
#' df_long <- simulate_long(
#' n_period = 10L * 4L,
#' n_revision = 5L,
#' periodicity = 4L,
#' start_period = as.Date("2010-01-01")
#' )
#'
#' ## Make analysis and generate the report
#'
#' vintages <- create_vintages(long_format, periodicity = 12L)
#' vintages <- create_vintages(df_long, periodicity = 4L, type = "long")
#' rslt <- revision_analysis(vintages, view = "diagonal")
#'
#' \dontrun{
#' render_report(
#' rslt,
#' output_file = "my_report",
#' output_dir = "C:/Users/xxx",
#' output_format = "pdf_document"
#' output_format = "pdf_document",
#' plot_revisions = TRUE
#' )
#' }
#'
render_report <- function(rslt,
output_file,
output_dir,
output_format = c("html_document", "pdf_document"),
open_report = TRUE,
...) {
render_report <- function(
rslt,
output_file,
output_dir,
output_format = c("html_document", "pdf_document", "word_document"),
plot_revisions = FALSE,
open_report = TRUE,
...) {

# Check input
checkmate::assert_class(rslt, "rjd3rev_rslts")
Expand All @@ -68,6 +74,8 @@ render_report <- function(rslt,
ext <- "html"
} else if (output_format == "pdf_document") {
ext <- "pdf"
} else if (output_format == "word_document") {
ext <- "docx"
}
}
output_file <- tools::file_path_sans_ext(output_file)
Expand All @@ -82,8 +90,11 @@ render_report <- function(rslt,
}

e <- list2env(list(
rslt = rslt,
descriptive_statistics = rslt$descriptive.statistics,
main_results = rslt$summary
main_results = rslt$summary,
add_plot = plot_revisions,
revisions = rslt$revisions
))

rmarkdown::render(
Expand Down
Loading

0 comments on commit 5e72a43

Please sign in to comment.