Type: | Package |
Title: | My Toolbox for Assisting Document Editing and Data Presenting |
Version: | 0.1.9 |
Description: | The purpose of this package is to share a collection of functions the author wrote during weekends for managing kitchen and garden tasks, e.g. making plant growth charts or Thanksgiving kitchen schedule charts, etc. Functions might include but not limited to: (1) aiding summarizing time related data; (2) generating axis transformation from data; and (3) aiding Markdown (with html output) and Shiny file editing. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
Depends: | R (≥ 4.1) |
Imports: | htmltools (≥ 0.4.0), ggplot2 (≥ 3.3.0), scales (≥ 1.0.0), data.table (≥ 1.14.2), labeling (≥ 0.3) |
Suggests: | rmarkdown (≥ 1.16), knitr, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
URL: | https://github.com/yh202109/mtb |
RoxygenNote: | 7.3.2 |
Language: | en-US |
LazyData: | true |
NeedsCompilation: | no |
Packaged: | 2025-02-28 17:20:30 UTC; yh2020 |
Author: | Y Hsu [aut, cre] |
Maintainer: | Y Hsu <yh202109@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-02-28 17:30:02 UTC |
Add a box with specified color in an R Markdown file.
Description
add_colored_box
returns a box component generated by htmltools
with specified color and styles.
Usage
add_colored_box(
type = "blue-default",
label = "",
info = "place details here using info option",
bgcolor = NULL,
width = 0.5,
halign = "c",
top = FALSE
)
Arguments
type |
One of:
|
label |
One of:
|
info |
A string including the main message of the box |
bgcolor |
NA or a length 3 vector with integer elements between 0 to 255 |
width |
NA or a number between 0.25 to 0.95 |
halign |
One of:
|
top |
One of:
|
Examples
add_colored_box( type='blue-default', info='the document include information regarding...')
Add a string with specified color or background color.
Description
add_colored_str
returns a string component generated by htmltools
with specified color and styles.
Usage
add_colored_str(
text = "",
color = c(51, 122, 183),
alpha = 255,
bgcolor = NULL,
bgalpha = 51,
fontsize = 1,
bold = FALSE,
it = FALSE
)
Arguments
text |
A string. default="". |
color |
One of
|
alpha |
An integer between 1 and 255 for text alpha. default=255. |
bgcolor |
One of
|
bgalpha |
An integer between 1 and 255 for background alpha. default=51. |
fontsize |
A real number between 0.5 and 5.0 for font size. default=1. |
bold |
A logical value for bold fonts. default= |
it |
A Boolean value for italic fonts. default= |
Value
a formatted string
Examples
add_colored_str("warning: read this message carefully.", color = c(255, 0, 0))
Check two tables with unique matching ids and generate reports on duplicated ids and repeated columns when applicable..
Description
bill_cross_check
returns a merged data.table showing
information regarding ids and repeated columns.
Usage
bill_cross_check(dt1 = NULL, dt2 = NULL, id = NULL, chk = NULL)
Arguments
dt1 |
A table. |
dt2 |
A table. |
id |
A column name or a vector of column names |
chk |
A column name |
Value
a data.table
Examples
bill_cross_check(data.frame(col1=c(1,2,3,3), col2=c('a','b','c','c'),
col3=c('-','=','+','-')),data.frame(col1=c(1,2,3), col2=c('a','b','c'),
col3=c('-','=','+')), id=c('col1','col2'), chk='col3')
Summarize times being purchased for individual items' from multiple grocery shopping lists.
Description
bill_cross_count
returns a data.table showing how many times each
items being listed on individual bills.
Usage
bill_cross_count(
ldt = list(),
id = NULL,
gp = NULL,
type = "count",
condstr = ""
)
Arguments
ldt |
A list of grocery tables in data.frame format. |
id |
A column name |
gp |
A column name or a vector of column names |
type |
A string in one of the following:
|
condstr |
A string for conditional counting |
Value
a data.table
Examples
bill_cross_count(list(cbind(col1=c('a','b','c'),col2=c(1,2,3)),
cbind(col1=c('d','c','d'),col2=c(4,5,6))), id='col1')
Generate a color vector
Description
Create a list of colors for a data vector by a list major colors.
Usage
color_set_palette(
vect = c(),
vectn = c(),
cols = c("blue", "cyan", "darkorange"),
black = "",
gray9 = ""
)
Arguments
vect |
A vector for groups. |
vectn |
An integer vector with length 0 or with the same length of |
cols |
One of
|
black |
A level in |
gray9 |
A level in |
Value
a named vector
Examples
color_set_palette( c('apple', 'orange', 'lime', 'apple'), c(2,1,3,2), 'red', 'blue')
Test a color vector
Description
Create a figure using the assigned color vector
Usage
color_test_palette(colvect = c(), type = "line")
Arguments
colvect |
A vector returned by |
type |
One of
|
Value
A plot
Examples
color_test_palette( setNames(c(1,2,3,4), c('apple','orange','avocado','lime') ))
Example dataset
Description
Example dataset
Author(s)
package author
Plot labeled events
Description
Create a plot for events with labels
Usage
time_plot_event(dt, xlab = "Time", anchor = TRUE, compact = FALSE)
Arguments
dt |
a
|
xlab |
A string for the x-axis title |
anchor |
A Boolean value for the vertical lines linking |
compact |
A Boolean value for reducing the vertical spacing when applicable |
Value
a plot
Examples
library(ggplot2)
dt = data.frame( id=paste('member',c(rep(c(1,2,3),each=3),3),sep=""),
idn=c(rep(1,3),rep(-1,3), rep(2,4)),
start=1800*c(0,1,2, 0.5, 1.2, 3, 1,2,3,4),
end=1800*c(2,NA,3, 2, 6, NA, 2,2.5,3, 3.5),
label=c(paste('event-',seq(1,10),sep='')),
labelend=c('','','?',')','','','','','>','X'),
type=c('b', 'p', 'i','i','p','p','p','b','i','i' ),
color=c('stove', 'oven', 'oven','oven','stove','oven','oven','other','stove','oven' )
)
time_plot_event( dt )
Plot periods of events
Description
Create a plot for event periods by ID
Usage
time_plot_interval(
dt,
xlab = "DateTime",
ylab = "ID",
legend_title = "Group",
arrow_wt = 1,
arrow_color = "black"
)
Arguments
dt |
a
|
xlab |
A string for the label of X-axis |
ylab |
A string for the label of Y-axis |
legend_title |
A string for the title of legend |
arrow_wt |
An integer for the weight of arrow |
arrow_color |
A string for the color of arrow |
Value
a plot
Examples
library(ggplot2)
dt = data.frame( id=c('ID01','ID12','ID3'), idn=c(1,3,2), start=1800*c(0,1,2), end=1800*c(2,-1,3),
label=c('A','B','C') )
time_plot_interval( dt, xlab='Time', ylab='ID', legend_title='Group', arrow_wt=3,
arrow_color='gray')
Transformation for continuous data with a finite number of distinct values
Description
trans_composition()
derives a transformation from a numerical vector with a smaller number (ideally < 30) of distinct values.
The return can be used with function ggplot::scale_x_continuous()
or ggplot::scale_y_continuous()
to create a desired axis.
Usage
trans_composition(x = NULL, nb = 30, brk = NA, dab = NA, dgrd = NA, dgrd2 = NA)
Arguments
x |
A numerical vector used in a plot as (typically) |
nb |
An integer for the maximum number of breaks. Default=30 |
brk |
One of
|
dab |
One of
|
dgrd |
One of
|
dgrd2 |
One of
|
Value
A transformation function
Examples
library(ggplot2)
pdt=data.frame(x=rep(c(0.5, 1, 10,11,12, 100, 1000), each=5))
pdt$y=pdt$x+rnorm(length(pdt$x))
t=trans_composition(pdt$x,brk=50, dab=3)
ggplot(pdt, aes(x=x, y=y))+geom_point()+scale_x_continuous(trans=t)
Transformation for continuous data with a finite number of distinct values
Description
trans_loglinear()
derives a log transformation from a numerical vector with a smaller number (ideally < 30) of distinct values..
The return can be used with function ggplot::scale_x_continuous()
or ggplot::scale_y_continuous()
to create a desired axis.
Usage
trans_loglinear(x = NULL, nb = 30, int = NA, scale = NA, mindist = 0.03)
Arguments
x |
A numerical vector used in a plot as (typically) |
nb |
An integer for the maximum number of breaks. Default=30 |
int |
One of
|
scale |
One of
|
mindist |
One of
|
Value
A transformation function
Examples
library(ggplot2)
pdt=data.frame(x=rep(c(0.5, 1, 10,11,12, 100, 1000), each=5))
pdt$y=pdt$x+rnorm(length(pdt$x))
t=trans_loglinear(pdt$x)
ggplot(pdt, aes(x=x, y=y))+geom_point()+scale_x_continuous(trans=t)