Package 'htmlreportR'

Title: 'HTML' Reporting Made Simple(R)
Description: Create compressed, interactive 'HTML' (Hypertext Markup Language) reports with embedded 'Python' code, custom 'JS' ('JavaScript') and 'CSS' (Cascading Style Sheets), and wrappers for 'CanvasXpress' plots, networks and more. Based on <https://pypi.org/project/py-report-html/>, its sister project.
Authors: Álvaro Esteban Martos [aut, cph, cre] , José Córdoba Caballero [aut, cph] , James Perkins [aut, cph] , Pedro Seoane Zonjic [aut, cph] , Jesús Pérez García [aut, cph]
Maintainer: Álvaro Esteban Martos <[email protected]>
License: GPL (>= 3)
Version: 1.0.1
Built: 2026-05-12 08:49:25 UTC
Source: https://github.com/aestebanmar/htmlreportr

Help Index


.add_id_column

Description

takes hash_vars, looks for a specific table, and adds its ID in a new column. Private method, use at your own risk.

Usage

.add_id_column(id, hash_vars, from_id_name, add_colnames = FALSE)

Arguments

id

hash_vars ID of table to process

hash_vars

plotter hash_vars slot

from_id_name

Name of column that contains original hash_vars IDs, to trace their origin. If NULL, this column will not be added.

add_colnames

A boolean. Controls colnames handling.

  • TRUE: tables' colnames are treated as such.

  • FALSE (the default): tables' first row is moved to colnames.


.prepare_standard_triplet_df

Description

Build triplet data frame for make_html_list function from three vectors. User should NEVER have to worry about this function

Usage

.prepare_standard_triplet_df(
  list_content,
  list_levels = NULL,
  list_types = NULL,
  default_type = "ul"
)

Arguments

list_content

Vector or list of elements with which to build the list

list_levels

Vector or list defining nesting levels. Default NULL

list_types

Vector or list with types to assign to each element ("ul" for unordered or "ol" for ordered).' If not supplied, default_type will determine list type for each element. Default NULL

default_type

List type to default if list_types is undefined, "ul" for unordered or "ol" for ordered. Default "ul"

Value

Data frame of contents, levels and types, ready for make_html_list.


Add Header and Row Names to Data Frame for HTML Report table

Description

This function modifies a data frame to include specific column and row names.

Arguments

data_frame

The data frame to be modified.

options

A list of options controlling the modification of column and row names.

Details

Add Header and Row Names to Data Frame for HTML Report table

This function checks the options provided and manipulates the column and row names of the input data frame accordingly. If the 'header' option is set to true, it assigns the first row of the data frame as column names and removes that row from the data frame. If the 'row_names' option is true, it assigns the first column of the data frame as row names and removes that column from the data frame. If either option is not true, it assigns sequential numbers as column or row names, respectively.

Value

The modified data frame with updated column and/or row names.


Build CanvasXpress barplot from R data frame

Description

Loads data frame and CanvasXpress options for barplot, then calls canvasXpress_main to build it.

Arguments

options

list with options.

Details

CanvasXpress barplot

Value

HTML code for CanvasXpress bar plot of data.


Build HTML Report Body

Description

This method builds the body of an HTML report by appending the specified body text to an htmlReport object.

Arguments

body_text

A character string containing the body text to be appended to the HTML report.

Details

Build HTML Report Body

Value

An updated htmlReport object with the specified body text appended to its body.


Build HTML report from template

Description

This function builds an HTML report from a given template file for an object of class "htmlReport".

Arguments

template

A character string specifying the file path of the template.

Details

Build HTML report from template

This function reads the contents of the template file, sets up Knitr options for rendering, renders the template using Knitr, and constructs the HTML report by combining the rendered template with the existing report content in the "htmlReport" object.

Value

A new instance of the htmlreportR class


col_to_rownames

Description

turns a column of the input data frame and turns it into its rownames, and then removes the actual column.

Usage

col_to_rownames(data_frame, col = 1)

Arguments

data_frame

Data frame to manipulate.

col

An integer. Col to set as new rowumns and remove from data frame.

Examples

col_to_rownames(tail(mtcars))

encode and compress data json

Description

compress_data

Arguments

data

string indicating object id

Value

encoded and compressed json


Custom addition operator for combining htmlReport objects

Description

This function defines a custom addition operator for combining two strings.

Arguments

value

An object of any type that can be coerced to character.

Details

Custom addition operator for combining htmlReport objects

Value

An object of class "htmlReport" with an updated @all_report which includes at the end the "value" string.


Build CanvasXpress density plot from R data frame

Description

Loads data frame and CanvasXpress options for density plot, then calls canvasXpress_main to build it.

Arguments

options

list with options.

Details

CanvasXpress density plot

Value

HTML code for CanvasXpress density plot of data.


Retrieve Data from htmlReport Object

Description

This method retrieves data from an htmlReport object based on specified options.

Arguments

options

A list containing options for data retrieval.

Details

Retrieve Data from htmlReport Object

Value

A list containing the retrieved data and additional information.


converts span noted table into a span map.

Description

get_col_n_row_span

Arguments

table

Colspan and rowspan maps.

Details

What we mean by "span map" is a table with the same dimensions as the input table, but with a number in each cell specifyin its column and row spans, respectively. A colspan of three means that it will merge with the two cells on its right into the same cell in the final table. Same logic for row span map, it will merge with the two cells below it.

Value

A list of two tables: colspans and rowspans.


Retrieve Data from htmlReport Object

Description

This method retrieves data from an htmlReport object based on specified options.

Arguments

options

A list containing options for data retrieval.

Value

A list containing the retrieved data and additional information.


Get Data for Plotting from htmlReport Object

Description

This method retrieves data suitable for plotting from an htmlReport object based on specified options.

Arguments

options

A list containing options for data retrieval.

Details

Get Data for Plotting from htmlReport Object

Value

A list containing the retrieved data, attributes, samples, and variables.


Get Plot from htmlReport Object

Description

This method generates and retrieves a plot from an htmlReport object. This code writes the plot to a temporal png, then it loads the png in base64 encoding and then displays the plot within the HTML report.

Arguments

plot_obj

A plot object like ggplot.

width

plot width

height

plot height

size_unit

units in plot size

img_properties

string including html properties of img

resizable

logical indicating if plot must be resizable

Details

Get Plot from htmlReport Object

Value

Displays the plot within the HTML report.


Get js Plot from canvasxpress_obj Object

Description

get_plot_data

Arguments

object_id

string indicating object id

cvXpress

vanvasXpress_obj object

Value

Displays the js code for plot.


get col and rowspan for a table element specified by indices.

Description

get_span

Arguments

colspan, rowspan

table of colspans and rowspans.

row, col

row and col indices of element whose spans to get.

Value

appended HTML code specifying element spans.


htmlReport reference class

Description

An htmlreporter reference class


Build CanvasXpress line plot from R data frame

Description

Loads data frame and CanvasXpress options for line plot, then calls canvasXpress_main to build it.

Arguments

options

list with options.

Details

CanvasXpress line plot

Value

HTML code for CanvasXpress line plot of data.


Build report by loading files from disk and rendering template.

Description

Main htmlreportR script mode function. Renders a template,

Usage

main_htmlreportR(options)

Arguments

options

list containing all necessary elements to build an htmlReport instance.

Details

Main htmlreportR scripting function

Value

None

Examples

## Not run: 
options <- list(title = "main_htmlreportR example",
			   data_files = "path/to/file1", "path/to/fileN",
			   output_file = "path/to/output",
			   source_folder = "path/to/package/scripts",
			   compress_obj = TRUE,
			   css_files = "path/to/custom/css",
			   js_files = "path/to/custom/js",
			   cdn_css = "path/to/cdn_css",
			   cdn_js = "path/to/cdn_js",
			   menu = "menu")
main_htmlreportR (options)

## End(Not run)

Make HTML Report Head

Description

This method generates the head section of an HTML report by adding the title to an htmlReport object.

Details

Make HTML Report Head

Value

An updated htmlReport object with the title added to its head section.


make_html_list

Description

Take an input vector or list and use it to build an html list of specified type

Usage

make_html_list(
  list_content,
  list_levels = NULL,
  list_types = NULL,
  default_type = "ul"
)

Arguments

list_content

Vector or list of elements with which to build the list

list_levels

Vector or list defining nesting levels. Default NULL

list_types

Vector or list with types to assign to each element ("ul" for unordered or "ol" for ordered).' If not supplied, default_type will determine list type for each element. Default NULL

default_type

List type to default if list_types is undefined, "ul" for unordered or "ol" for ordered. Default "ul"

Value

Formatted html list ready to render.

Examples

content <- c("One", "Two", "Three")
make_html_list(list_content = content)

binds tables contained in hash_vars by rows

Description

merge_hashed_tables

Arguments

ids

Vector of hash_vars IDs to bind.

join_method

Method by which tables will be joined, default "rbind". also admits "cbind", in which case from_id_name and alt_ids arguments will be ignored.

add_colnames

A boolean. Controls colnames handling.

  • TRUE: tables' colnames are treated as such.

  • FALSE (the default): tables' first row is moved to colnames.

from_id_name

Name of column that contains original hash_vars IDs, to trace their origin. If NULL, this column will not be added.

alt_ids

New names for original IDs column, in case renaming them is needed for clarity, for example. If NULL (the default) they will not be renamed.

target_id

Hash_vars ID where output will be saved. If NULL (the default) it will be returned and NOT saved.

Value

Merged table


Print data frame in HTML format

Description

Parses a data frame included in an object of class "htmlReport" and HTML table to include it in htmlreportR

Arguments

data_frame

Data frame to parse

options

list with options

table_id

An integer. Table id in report

row_names

A boolean.

  • TRUE (the default): Parse data frame row names as a column of the HTML table.

  • FALSE (the default): Do not parse data frame row names.

colspan, rowspan

Mirrors of input data_frame specifying spans.

Details

Parse data frame to HTML

Value

A table in html format.


parse_paths

Description

takes a vector of comma-separated paths and parses it so files can be loaded. If any of the paths contain wildcards, they will be expanded.

Usage

parse_paths(string)

Arguments

string

String containing paths to expand.

Examples

## Not run: 
        parse_paths("./*/test*txt")
       
## End(Not run)

Encapsulates input code in div of specified characteristics

Description

pretiffy_div

Arguments

code

Code to envelop in div

overflow, display, direction, justify, height, width

HTML div parameters. for height and width you should include the unit.

preset

Preset to inject. Currently only "magic" exists.

inject_string

Directly inject a custom string as div.

Value

Customized div.

Examples

text <- "I am a div"
plotter <- htmlReport$new()
pretty_div <- plotter$prettify_div(code = text, preset = "magic")

replace_paired_mark

Description

Recursively replaces paired marks in a string.

Usage

replace_paired_mark(string, pattern, replace)

Arguments

string

String to edit

pattern

Pattern to recursively replace

replace

Vector containing, in that order, expression that will replace the first paired element and the second paired element

Value

Modified string.

Examples

example_string <- "** This should be in bold **"
pattern <- "(\\*\\*+?)([- \\w]+)(\\*\\*+?)"
replace_paired_mark(example_string, pattern, c("<strong>", "</strong>"))

row_to_header

Description

turns a row of the input data frame and turns it into its colnames, and then removes the actual row.

Usage

row_to_header(data_frame, row = 1)

Arguments

data_frame

Data frame to manipulate.

row

An integer. Row to set as new columns and remove from data frame.

Examples

row_to_header(head(mtcars))

Build CanvasXpress scatter2D plot from R data frame

Description

Loads data frame and CanvasXpress options for scatter2D plot, then calls canvasXpress_main to build it.

Arguments

options

list with options.

Details

CanvasXpress scatter2D plot

Value

HTML code for CanvasXpress scatter2D plot of data.


Build CanvasXpress scatter3D plot from R data frame

Description

Loads data frame and CanvasXpress options for scatter3D plot, then calls canvasXpress_main to build it.

Arguments

options

list with options.

Details

CanvasXpress scatter3D plot

Value

HTML code for CanvasXpress scatter3D plot of data.


Generate static ggplot for HTML report

Description

This function generates a static ggplot for inclusion in an HTML report for an object of class "htmlReport".

Arguments

id

A character string specifying the identifier for the element of hash_vars that is taken.

header

Logical, indicating whether the dataset has a header row.

row_names

Logical, indicating whether to include row names.

transpose

Logical, indicating whether to transpose the dataset.

smp_attr

A list of attributes for samples.

var_attr

A list of attributes for variables.

fields

A character vector specifying fields to include in the ggplot.

func

A function to preprocess data before plotting.

plotting_function

A function used for generating the ggplot.

text

Logical, indicating whether to convert table to text or a vector indicating the numeric fields.

width

plot width

height

plot height

size_unit

units in plot size

img_properties

string including html properties of img

resizable

logical indicating if plot must be resizable

Details

Generate static ggplot for HTML report

This function generates a static ggplot based on the provided data and plot specifications. It first defines a wrapper function for ggplot generation, then calls the static_plot_main function to generate the plot and include it in the HTML report object.


Generate static plot for HTML report

Description

This function generates a static plot for inclusion in an HTML report for an object of class "htmlReport".

Arguments

id

A character string specifying the identifier for the plot included in hash_vars.

header

Logical, indicating whether the dataset has a header row.

row_names

Logical, indicating whether to include row names.

transpose

Logical, indicating whether to transpose the dataset.

smp_attr

A list of attributes for samples.

var_attr

A list of attributes for variables.

fields

A character vector specifying the fields to include in the plot.

func

A function to preprocess data before plotting.

plotting_function

A function used for generating the plot.

plotting_args

Named list of arguments to pass to plotting function in addition to input data.

text

Logical, indicating whether to convert table to text or a vector indicating the numeric fields.

custom_format

Logical, indicating if id correspond to a table or a custom object

width

plot width

height

plot height

size_unit

units in plot size

img_properties

string including html properties of img

resizable

logical indicating if plot must be resizable

Details

Generate static plot for HTML report

This function generates a static plot based on the provided data and plot specifications. It first retrieves the data frame for plotting using the provided options, preprocesses the data if a preprocessing function is specified, generates the plot using the provided plotting function, and then adds the plot to the HTML report object.


Generate table from plotter object with specified options

Description

This method takes a list of options to build a table from a htmlReport object.

Arguments

options

list with options

Details

Table method for htmlReport class

Value

A string encoding a html table.


Write HTML Report

Description

This method writes the HTML report generated by an htmlReport object to a specified output file path.

Arguments

output_path

A character string specifying the output file path for the HTML report.

Details

Write HTML Report

Value

Writes the HTML report to the specified output file path and removes temporary files.