From 41434ad26e8b96135ddea36571c56e1842cff799 Mon Sep 17 00:00:00 2001 From: vertesy Date: Thu, 24 Oct 2024 16:01:25 +0200 Subject: [PATCH] new release --- CITATION.cff | 2 +- DESCRIPTION | 4 +- Development/config.R | 4 +- R/MarkdownReports.R | 37 ++++++----- README.md | 154 ++++++++++++++++++------------------------- man/check_OutDir.Rd | 4 -- man/whist.Rd | 1 + 7 files changed, 92 insertions(+), 114 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 0f70371..c2d3b0b 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,6 +1,6 @@ cff-version: 1.2.0 title: vertesy/MarkdownReports v4.3.2 Type Less, Plot More. Create (scientific) plots with very little code and write (markdown) reports easily from your R scripts. -version: v4.7.1 +version: v4.8.0 message: >- If you use this software, please cite it using these metadata. type: software diff --git a/DESCRIPTION b/DESCRIPTION index 4320ada..893c236 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MarkdownReports Title: Generate Scientific Figures and Reports Easily -Version: 4.7.1 +Version: 4.8.0 Authors@R: person("Abel", "Vertesy", , "av@imba.oeaw.ac.at", role = c("aut", "cre")) Author: Abel Vertesy [aut, cre] @@ -34,6 +34,6 @@ Imports: VennDiagram, vioplot Encoding: UTF-8 -Packaged: 2024-05-03 19:06:48.366226 +Packaged: 2024-10-24 16:00:45.369786 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 diff --git a/Development/config.R b/Development/config.R index 20014ca..5c7f1c5 100644 --- a/Development/config.R +++ b/Development/config.R @@ -1,7 +1,9 @@ # Configuration for the Package +# file.edit("~/GitHub/Packages/XXXXXXXXXX/Development/config.R") + DESCRIPTION <- list( package.name = "MarkdownReports", - version = "4.7.1", + version = "4.8.0", title = "Generate Scientific Figures and Reports Easily", description = "MarkdownReports is a set of R functions that allows you to generate precise figures easily, and create clean markdown reports about what you just discovered with your analysis script. It helps you to: diff --git a/R/MarkdownReports.R b/R/MarkdownReports.R index 7224d8f..e22ce9d 100644 --- a/R/MarkdownReports.R +++ b/R/MarkdownReports.R @@ -261,10 +261,16 @@ create_set_SubDir <- function(..., define.ParentDir = TRUE, } if (define.ParentDir) { if (exists("ParentDir")) { # If this function has been run already, you have "ParentDir", which will be overwritten. - if (verbose) { print("ParentDir was defined as:"); message(ParentDir) } + if (verbose) { + print("ParentDir was defined as:") + message(ParentDir) + } } # if - if (verbose) { print("ParentDir will be:"); message(OutDir) } + if (verbose) { + print("ParentDir will be:") + message(OutDir) + } MarkdownHelpers::ww.assign_to_global("ParentDir", OutDir, 1) } # if if (verbose) print("Call *create_set_Original_OutDir()* when chaning back to the main dir.") @@ -334,9 +340,6 @@ continue_logging_markdown <- function(b.scriptname) { #' specified directory (OutDir). If they do not match, it prints both directories to the #' screen. #' -#' @param OutDir The target directory to compare with the current working directory. -#' Default: OutDir (assumes that OutDir should be defined in the global environment). -#' #' @return Prints a message to the console if the current working directory does not #' match OutDir. No return value. #' @@ -346,8 +349,8 @@ continue_logging_markdown <- function(b.scriptname) { #' @importFrom checkmate assertCharacter #' @export check_OutDir <- function() { - # Get the current working directory - current_dir <- paste0(getwd(),"/") + # Get the current working directory + current_dir <- paste0(getwd(), "/") # Check if OutDir is defined and if current_dir is not equal to OutDir if (!exists("OutDir")) { @@ -445,18 +448,19 @@ wplot_save_pheatmap <- function(x, suffix = "heatmap", plotname = as.character(substitute(x)), add = 1, - width = max(if(is.null(data)) 7 else ncol(data) + add, 4), - height = max(if(is.null(data)) 7 else nrow(data) - add, 4), + width = max(if (is.null(data)) 7 else ncol(data) + add, 4), + height = max(if (is.null(data)) 7 else nrow(data) - add, 4), pdf = TRUE, png = FALSE, png_res = 100, # NA png_dim_factor = 100, mdlink = TRUE) { # - stopifnot(inherits(x, "pheatmap"), - is.character(suffix), is.character(plotname), nchar(plotname) < 200, - is.numeric(add), is.numeric(width), is.numeric(height), - is.logical(pdf), is.logical(png), is.numeric(png_res), is.numeric(png_dim_factor), is.logical(mdlink) + stopifnot( + inherits(x, "pheatmap"), + is.character(suffix), is.character(plotname), nchar(plotname) < 200, + is.numeric(add), is.numeric(width), is.numeric(height), + is.logical(pdf), is.logical(png), is.numeric(png_res), is.numeric(png_dim_factor), is.logical(mdlink) ) message("width: ", width, "; height: ", height, "\nplotname: ", plotname, "; suffix: ", suffix) @@ -1094,13 +1098,16 @@ wbarplot <- function(variable, #' @param mdlink Insert a .pdf and a .png image link in the markdown report, set by #' "path_of_report". #' @param PNG Set to true if you want to save the plot as PNG instead of the default PDF. -#' @export -#' @examples MyGauss <- rnorm(1000) +#' +#' @examples +#' MyGauss <- rnorm(1000) #' whist( #' variable = MyGauss, col = "gold1", w = 7, #' breaks = 20, mdlink = FALSE, hline = FALSE, vline = FALSE, lty = 2, lwd = 3, #' lcol = 2, filtercol = 0 #' ) +#' +#' @export whist <- function(variable, ..., breaks = 20, diff --git a/README.md b/README.md index 81a51bd..90dbc69 100644 --- a/README.md +++ b/README.md @@ -208,129 +208,101 @@ end ----- -## List of Functions (30) - -Updated: 2023/11/27 00:51 +## List of Functions in MarkdownReports (31) +Updated: 2024/10/24 15:57 - #### 1 `setup_MarkdownReports()` +Setup Markdown Reports. Initializes the markdown report file and the output directory. This function creates a subdirectory in "OutDir", named with the script name and the modification time. It also defines the "path_of_report" variable used by all log-writing and wplot functions. - setup_MarkdownReports. Setup the markdown report file and the output directory, create a sub directory in "OutDir". Its name is stamped with the script name and the modification time. Create the "path_of_report" variable used by all log-writing and ~wplot functions. - -- #### 2 `create_set_SubDir()` - - Create_set_SubDir. Create or set the output directory of the script, and set the "NewOutDir" variable that is used by all ~wplot functions. Opening pair of the create_set_Original_OutDir function. - -- #### 3 `create_set_Original_OutDir()` - - create_set_Original_OutDir. Closing pair of the create_set_SubDir function. Call when chaning back to the main dir. Set the output directory of the script, and set the "NewOutDir" variable that is used by all ~wplot functions. - -- #### 4 `continue_logging_markdown()` - - continue_logging_markdown. Continue writing to an existing report file. - -- #### 5 `create_set_OutDir()` - - create_set_OutDir. Create or set the output directory of the script, and set the "OutDir" variable that is used by all ~wplot functions. - -- #### 6 `wplot_save_this()` - - wplot_save_this. Save the currently active graphic device (for complicated plots). Insert links to your markdown report, set by "path_of_report". Name the file by naming the variable! - -- #### 7 `wplot_save_pheatmap()` - - wplot_save_pheatmap. Save pheatmap object. Modified from: https://stackoverflow.com/questions/43051525/how-to-draw-pheatmap-plot-to-screen-and-also-save-to-file - -- #### 8 `wplot()` - - wplot. Create and save scatter plots as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. The .png version is not created, only the link is put in place. You can add 2D error bars around the dots, or add lines (ablines) to your plot, by setting "abline" argument to = FALSE (no line, default), "h" (horizontal, further specified by a = y-offset), "v" (vertical, further specified by a = x-offset), "ab" (line with an angle, further specified by a = offset, b = slope). - -- #### 9 `wscatter.fill()` - - wscatter.fill. A scatterplot with color gradient and color legend. Modified from: http://stackoverflow.com/questions/20127282/r-color-scatterplot-points-by-col-value-with-legend - -- #### 10 `wbarplot()` - - wbarplot. Create and save bar plots as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - -- #### 11 `whist()` - - whist. Create and save histograms as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. Name the file by naming the variable! Cannot be used with dynamically called variables [e.g. call vectors within a loop]. "filtercol" assumes >= coloring! - -- #### 12 `wboxplot()` - - wboxplot. Create and save box plots as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - -- #### 13 `wpie()` - - wpie. Create and save pie charts as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - -- #### 14 `wstripchart()` - - wstripchart. Create and save strip charts as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - -- #### 15 `wstripchart_list()` - - wstripchart_list. Create and save stripcharts from a list as .pdf, in "OutDir". This version allows individual coloring of each data point, by a color-list of the same dimension. If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - -- #### 16 `wvioplot_list()` +- #### 2 `create_set_OutDir()` +create_set_OutDir. Create or set the output directory of the script, and set the "OutDir" variable that is used by all ~wplot functions. - wvioplot_list. Create and save violin plots as .pdf, in "OutDir". It requires (and calls) "vioplot" package. If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. +- #### 3 `create_set_SubDir()` +Create_set_SubDir. Create or set the output directory of the script, and set the "NewOutDir" variable that is used by all ~wplot functions. Opening pair of the create_set_Original_OutDir function. -- #### 17 `wviostripchart_list()` +- #### 4 `create_set_Original_OutDir()` +create_set_Original_OutDir. Closing pair of the create_set_SubDir function. Call when chaning back to the main dir. Set the output directory of the script, and set the "NewOutDir" variable that is used by all ~wplot functions. - wviostripchart_list. Create and save violin plots as .pdf, in "OutDir". It requires (and calls) "vioplot" package. If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. +- #### 5 `continue_logging_markdown()` +continue_logging_markdown. Continue writing to an existing report file. -- #### 18 `wvenn()` +- #### 6 `check_OutDir()` +Compare Current Working Directory with OutDir. This function checks if the current working directory is the same as a specified directory (OutDir). If they do not match, it prints both directories to the screen. - wvenn. Save venn diagrams. Unlike other ~vplot funcitons, this saves directly into a .png, and it does not use the dev.copy2pdf() function. +- #### 7 `wplot_save_this()` +wplot_save_this. Save the currently active graphic device (for complicated plots). Insert links to your markdown report, set by "path_of_report". Name the file by naming the variable! -- #### 19 `wbarplot_dfCol()` +- #### 8 `wplot_save_pheatmap()` +wplot_save_pheatmap. Save pheatmap object. Modified from: https://stackoverflow.com/questions/43051525/how-to-draw-pheatmap-plot-to-screen-and-also-save-to-file - wbarplot_dfCol. wbarplot for a column of a data frame. +- #### 9 `wplot()` +wplot. Create and save scatter plots as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. The .png version is not created, only the link is put in place. You can add 2D error bars around the dots, or add lines (ablines) to your plot, by setting "abline" argument to = FALSE (no line, default), "h" (horizontal, further specified by a = y-offset), "v" (vertical, further specified by a = x-offset), "ab" (line with an angle, further specified by a = offset, b = slope). -- #### 20 `whist_dfCol()` +- #### 10 `wscatter.fill()` +wscatter.fill. A scatterplot with color gradient and color legend. Modified from: http://stackoverflow.com/questions/20127282/r-color-scatterplot-points-by-col-value-with-legend - whist_dfCol. Use this version of whist() if you iterate over columns or rows of a data frame. You can name the file by naming the variable. Cannot be used with dynamically called variables (e.g. call vectors within a loop). +- #### 11 `wbarplot()` +wbarplot. Create and save bar plots as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. -- #### 21 `pdfA4plot_on()` +- #### 12 `whist()` +whist. Create and save histograms as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. Name the file by naming the variable! Cannot be used with dynamically called variables [e.g. call vectors within a loop]. "filtercol" assumes >= coloring! - pdfA4plot_on. Create A4 PDFs to plot multiple subplots in one file +- #### 13 `wboxplot()` +wboxplot. Create and save box plots as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. -- #### 22 `pdfA4plot_on.layout()` +- #### 14 `wpie()` +wpie. Create and save pie charts as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - pdfA4plot_on.layout. Create A4 PDFs to plot multiple subplots in one file with custom numbers of columns in each row. Fancy layout version of pdfA4plot_on() +- #### 15 `wstripchart()` +wstripchart. Create and save strip charts as .pdf, in "OutDir". If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. -- #### 23 `pdfA4plot_off()` +- #### 16 `wstripchart_list()` +wstripchart_list. Create and save stripcharts from a list as .pdf, in "OutDir". This version allows individual coloring of each data point, by a color-list of the same dimension. If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - pdfA4plot_off. The pair of the "pdfA4plot_on()" function; to finish plotting in the A4 pdf. @importFrom clipr write_clip @examples pdfA4plot_on.layout(plotname = "MyA4_w_layout") hist(rnorm(100)) hist(-rnorm(100)) hist(10 + rnorm(100)) pdfA4plot_off() +- #### 17 `wvioplot_list()` +wvioplot_list. Create and save violin plots as .pdf, in "OutDir". It requires (and calls) "vioplot" package. If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. -- #### 24 `error_bar()` +- #### 18 `wviostripchart_list()` +wviostripchart_list. Create and save violin plots as .pdf, in "OutDir". It requires (and calls) "vioplot" package. If mdlink = TRUE, it inserts a .pdf and a .png link in the markdown report, set by "path_of_report". The .png version is not created, only the link is put in place, not to overwrite previous versions. - error_bar. Put error bars on top of your bar plots. This functionality is now integrated into MarkdownReporter's wbarplot() function +- #### 19 `wvenn()` +wvenn. Save venn diagrams. Unlike other ~vplot funcitons, this saves directly into a .png, and it does not use the dev.copy2pdf() function. -- #### 25 `wlegend()` +- #### 20 `wbarplot_dfCol()` +wbarplot_dfCol. wbarplot for a column of a data frame. - wlegend. Quickly add a legend to an existing plot, and save the plot immediately. +- #### 21 `whist_dfCol()` +whist_dfCol. Use this version of whist() if you iterate over columns or rows of a data frame. You can name the file by naming the variable. Cannot be used with dynamically called variables (e.g. call vectors within a loop). -- #### 26 `wlegend.label()` +- #### 22 `pdfA4plot_on()` +pdfA4plot_on. Create A4 PDFs to plot multiple subplots in one file - wlegend.label. Quickly add a "text only" legend without a filled color box. to an existing plot, and save the plot immediately. Never inserts an mdlink. +- #### 23 `pdfA4plot_on.layout()` +pdfA4plot_on.layout. Create A4 PDFs to plot multiple subplots in one file with custom numbers of columns in each row. Fancy layout version of pdfA4plot_on() -- #### 27 `barplot_label()` +- #### 24 `pdfA4plot_off()` +pdfA4plot_off. The pair of the "pdfA4plot_on()" function; to finish plotting in the A4 pdf. @importFrom clipr write_clip @examples pdfA4plot_on.layout(plotname = "MyA4_w_layout") hist(rnorm(100)) hist(-rnorm(100)) hist(10 + rnorm(100)) pdfA4plot_off() - barplot_label. Add extra labels to your bar plots at the top or the base. +- #### 25 `error_bar()` +error_bar. Put error bars on top of your bar plots. This functionality is now integrated into MarkdownReporter's wbarplot() function -- #### 28 `wLinRegression()` +- #### 26 `wlegend()` +wlegend. Quickly add a legend to an existing plot, and save the plot immediately. - wLinRegression. Add linear regression, and descriptors to line to your scatter plot. Provide the same dataframe as you provided to wplot() before you called this function +- #### 27 `wlegend.label()` +wlegend.label. Quickly add a "text only" legend without a filled color box. to an existing plot, and save the plot immediately. Never inserts an mdlink. -- #### 29 `subscript_in_plots()` +- #### 28 `barplot_label()` +barplot_label. Add extra labels to your bar plots at the top or the base. - subscript_in_plots. Returns a formatted string that you feed to main, xlab or ylab parameters of a plot Create an expression with subscript for axis labels. Parsed when provided to xlab or ylab of a function. +- #### 29 `wLinRegression()` +wLinRegression. Add linear regression, and descriptors to line to your scatter plot. Provide the same dataframe as you provided to wplot() before you called this function -- #### 30 `superscript_in_plots()` +- #### 30 `subscript_in_plots()` +subscript_in_plots. Returns a formatted string that you feed to main, xlab or ylab parameters of a plot Create an expression with subscript for axis labels. Parsed when provided to xlab or ylab of a function. - superscript_in_plots. Returns a formatted string that you feed to main, xlab or ylab parameters of a plot Create an expression with superscript for axis labels. Parsed when provided to xlab or ylab of a function. +- #### 31 `superscript_in_plots()` +superscript_in_plots. Returns a formatted string that you feed to main, xlab or ylab parameters of a plot Create an expression with superscript for axis labels. Parsed when provided to xlab or ylab of a function. diff --git a/man/check_OutDir.Rd b/man/check_OutDir.Rd index e5e1c41..c73e656 100644 --- a/man/check_OutDir.Rd +++ b/man/check_OutDir.Rd @@ -6,10 +6,6 @@ \usage{ check_OutDir() } -\arguments{ -\item{OutDir}{The target directory to compare with the current working directory. -Default: OutDir (assumes that OutDir should be defined in the global environment).} -} \value{ Prints a message to the console if the current working directory does not match OutDir. No return value. diff --git a/man/whist.Rd b/man/whist.Rd index b1685d9..3c63bfa 100644 --- a/man/whist.Rd +++ b/man/whist.Rd @@ -83,4 +83,5 @@ whist( breaks = 20, mdlink = FALSE, hline = FALSE, vline = FALSE, lty = 2, lwd = 3, lcol = 2, filtercol = 0 ) + }