Skip to content

Commit

Permalink
Merge pull request #20 from AQLT/master
Browse files Browse the repository at this point in the history
Print style
  • Loading branch information
palatej authored Sep 13, 2018
2 parents 81e2157 + 3154237 commit dc0b233
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
^\.Rproj\.user$
^README\.Rmd$
^README-.*\.png$
.travis.yml
7 changes: 4 additions & 3 deletions R/export_workspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ new_workspace <- function() {
new_multiprocessing <- function(workspace, name) {
mp <- .jcall(workspace, "Lec/tstoolkit/jdr/ws/MultiProcessing;", "newMultiProcessing", name)
mp <- new("multiprocessing", mp)
return(mp)
return(invisible(mp))
}


Expand Down Expand Up @@ -124,12 +124,13 @@ add_sa_item <- function(workspace, multiprocessing, sa_obj, name){
if (! is.numeric(multiprocessing))
stop("The parameter multiprocessing must be a character or a numeric")

if(missing(name))
name <- deparse(substitute(sa_obj))

sa_obj <- complete_dictionnary(workspace, sa_obj)
jspec <- get_jspec(sa_obj)
y <- sa_obj$final$series[, "y"]

if(missing(name))
name <- deparse(substitute(sa_obj))

if(!is.character(name) || length(name) != 1)
stop("The name of the SA element to add is mispecified")
Expand Down
65 changes: 46 additions & 19 deletions R/sa_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ print.decomposition_X11=function (x, digits = max(3L, getOption("digits") - 3L),
cat("\n")
}
#' @export
print.decomposition_SEATS=function (x, digits = max(3L, getOption("digits") - 3L), ...){

print.decomposition_SEATS=function (x, digits = max(3L, getOption("digits") - 3L),
enable_print_style = TRUE,...){
if(enable_print_style){
bold_pre_code <- "\033[1m"
bold_post_code <- "\033[22m"
}else{
bold_pre_code <- bold_post_code <- ""
}
model <-x$model$model
sa <- x$model$sa
t <- x$model$trend
Expand All @@ -29,7 +35,8 @@ print.decomposition_SEATS=function (x, digits = max(3L, getOption("digits") - 3L

for (ii in 1:length(var_names)){
if (!all(sapply(var[[ii]],is.null))){
cat("\033[1m",var_names[ii],"\033[22m","\n", sep="")
cat(bold_pre_code,var_names[ii],bold_post_code,"\n", sep="")

print_formula(var[[ii]][1,-1],"AR")
print_formula(var[[ii]][2,-1],"D")
print_formula(var[[ii]][3,-1],"MA")
Expand Down Expand Up @@ -86,15 +93,23 @@ print.combined_test <- function(x, digits = max(3L, getOption("digits") - 3L),

#' @export
print.diagnostics = function (x, digits = max(3L, getOption("digits") - 3L),
enable_print_style = TRUE,
...){


if(enable_print_style){
bold_pre_code <- "\033[1m"
bold_post_code <- "\033[22m"
}else{
bold_pre_code <- bold_post_code <- ""
}
residuals_test <- x$residuals_test
combined_test_all <- x$combined_test_all
combined_test_end <- x$combined_test_end
variance_decomposition <- x$variance_decomposition

cat("\033[1mRelative contribution of the components to the stationary portion of the variance in the original series, after the removal of the long term trend\033[22m")
cat(bold_pre_code,
"Relative contribution of the components to the stationary portion of the variance in the original series, after the removal of the long term trend",
bold_post_code)
cat("\n")
cat(" Trend computed by Hodrick-Prescott filter (cycle length = 8.0 years)")
cat("\n")
Expand All @@ -104,7 +119,9 @@ print.diagnostics = function (x, digits = max(3L, getOption("digits") - 3L),
)),
sep ="\n")
cat("\n")
cat("\033[1mResidual seasonality tests\033[22m")
cat(bold_pre_code,
"Residual seasonality tests",
bold_post_code)
cat("\n")
cat(paste0(" ",
capture.output(
Expand All @@ -116,7 +133,9 @@ print.diagnostics = function (x, digits = max(3L, getOption("digits") - 3L),

cat("\n")

cat("\033[1mCombined test in the entire series\033[22m")
cat(bold_pre_code,
"Combined test in the entire series",
bold_post_code)
cat("\n")
cat(paste0(" ",
capture.output(print.combined_test(combined_test_all, digits = digits,
Expand All @@ -125,7 +144,9 @@ print.diagnostics = function (x, digits = max(3L, getOption("digits") - 3L),
sep ="\n")
cat("\n")

cat("\033[1mCombined test in the last 3 years\033[22m")
cat(bold_pre_code,
"Combined test in the last 3 years",
bold_post_code)
cat("\n")
cat(paste0(" ",
capture.output(
Expand Down Expand Up @@ -156,7 +177,7 @@ print.final <- function(x, calendar, n_last_obs = frequency(x$series), print_for
invisible(x)
}
#' @export
print.user_defined <- function(x,...){
print.user_defined <- function(x, ...){
if(is.null(x) || length(x) == 0)
return(invisible(x))
cat(ngettext((length(x)!= 1) + 1,
Expand All @@ -167,16 +188,22 @@ print.user_defined <- function(x,...){
invisible(x)
}
#' @export
print.SA <- function(x,...){
cat("\n\n","\033[4m\033[1mRegARIMA\033[22m\033[24m","\n",sep="")
print(x$regarima)
cat("\n\n","\033[4m\033[1mDecomposition\033[22m\033[24m","\n",sep="")
print(x$decomposition)
cat("\n\n","\033[4m\033[1mFinal\033[22m\033[24m","\n",sep="")
print(x$final)
cat("\n\n","\033[4m\033[1mDiagnostics\033[22m\033[24m","\n",sep="")
print(x$diagnostics)
cat("\n\n","\033[4m\033[1mAdditional output variables\033[22m\033[24m","\n",sep="")
print.SA <- function(x, enable_print_style = TRUE, ...){
if(enable_print_style){
style_pre_code <- "\033[4m\033[1m"
style_post_code <- "\033[22m\033[24m"
}else{
style_pre_code <- style_post_code <- ""
}
cat("\n\n", style_pre_code, "RegARIMA", style_post_code,"\n",sep="")
print(x$regarima, enable_print_style = enable_print_style)
cat("\n\n", style_pre_code, "Decomposition", style_post_code,"\n",sep="")
print(x$decomposition, enable_print_style = enable_print_style)
cat("\n\n", style_pre_code, "Final", style_post_code,"\n",sep="")
print(x$final, enable_print_style = enable_print_style)
cat("\n\n", style_pre_code, "Diagnostics", style_post_code,"\n",sep="")
print(x$diagnostics, enable_print_style = enable_print_style)
cat("\n\n", style_pre_code, "Additional output variables", style_post_code,"\n",sep="")
print(x$user_defined)
}

0 comments on commit dc0b233

Please sign in to comment.