This addin links to a downloadable PDF version of the baRcodeR cheatsheet.
cheatsheet()
cheatsheet()
Opens webpage of PDF
if(interactive()){ baRcodeR::cheatsheet() }
if(interactive()){ baRcodeR::cheatsheet() }
Input vector or data.frame of ID codes to produce a PDF of QR codes which can
be printed. This is a wrapper function for custom_create_PDF
.
See details of custom_create_PDF
on how to format text labels
if needed.
create_PDF( user = FALSE, Labels = NULL, name = "LabelsOut", type = "matrix", ErrCorr = "H", Fsz = 12, ... )
create_PDF( user = FALSE, Labels = NULL, name = "LabelsOut", type = "matrix", ErrCorr = "H", Fsz = 12, ... )
user |
logical. Run function using interactive mode (prompts user for
parameter values) Default is |
Labels |
vector or data frame object containing label names (i.e. unique ID codes) with either UTF-8 or ASCII encoding. |
name |
character. Name of the PDF output file. Default is
|
type |
character. Choice of |
ErrCorr |
error correction value for matrix labels only. Level of damage
from low to high: |
Fsz |
numerical. Sets font size in points. Longer ID codes may be shrunk
to fit if truncation is not used for matrix labels. Default font size is
|
... |
advanced arguments to modify the PDF layout. See
|
The default PDF setup is for ULINE 1.75" * 0.5" WEATHER RESISTANT LABEL for laser
printer; item # S-19297 (uline.ca). The page format can be modified using
the ...
(advanced arguments) for other label types.
a PDF file containing QR-coded labels, saved to the default directory.
## data frame example_vector <- as.data.frame(c("ao1", "a02", "a03")) ## Not run: ## run with default options ## pdf file will be "example.pdf" saved into a temp directory temp_file <- tempfile() create_PDF(Labels = example_vector, name = temp_file) ## view example output from temp folder system2("open", paste0(temp_file, ".pdf")) ## End(Not run) ## run interactively. Overrides default pdf options if(interactive()){ create_PDF(user = TRUE, Labels = example_vector) } ## Not run: ## run using a data frame, automatically choosing the "label" column example_df <- data.frame("level1" = c("a1", "a2"), "label" = c("a1-b1", "a1-b2"), "level2" = c("b1", "b1")) create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_2")) ## End(Not run) ## Not run: ## run using an unnamed data frame example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame create_PDF(user = FALSE, Labels = example_df[,2], name = file.path(tempdir(), "example_3")) ## End(Not run) ## Not run: ## create linear (code128) label rather than matrix (2D/QR) labels example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_4", type = "linear")) ## End(Not run)
## data frame example_vector <- as.data.frame(c("ao1", "a02", "a03")) ## Not run: ## run with default options ## pdf file will be "example.pdf" saved into a temp directory temp_file <- tempfile() create_PDF(Labels = example_vector, name = temp_file) ## view example output from temp folder system2("open", paste0(temp_file, ".pdf")) ## End(Not run) ## run interactively. Overrides default pdf options if(interactive()){ create_PDF(user = TRUE, Labels = example_vector) } ## Not run: ## run using a data frame, automatically choosing the "label" column example_df <- data.frame("level1" = c("a1", "a2"), "label" = c("a1-b1", "a1-b2"), "level2" = c("b1", "b1")) create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_2")) ## End(Not run) ## Not run: ## run using an unnamed data frame example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame create_PDF(user = FALSE, Labels = example_df[,2], name = file.path(tempdir(), "example_3")) ## End(Not run) ## Not run: ## create linear (code128) label rather than matrix (2D/QR) labels example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_4", type = "linear")) ## End(Not run)
Input a vector or data frame of ID codes to produce a PDF of barcode labels that can then be printed. The PDF setup is for the ULINE 1.75" * 0.5" WEATHER RESISTANT LABEL for laser printer; item # S-19297 (uline.ca). See details for how to format text labels properly.
custom_create_PDF( user = FALSE, Labels = NULL, name = "LabelsOut", type = "matrix", ErrCorr = "H", Fsz = 12, Across = TRUE, ERows = 0, ECols = 0, trunc = TRUE, numrow = 20, numcol = 4, page_width = 8.5, page_height = 11, width_margin = 0.25, height_margin = 0.5, label_width = NA, label_height = NA, x_space = 0, y_space = 0.5, alt_text = NULL, replace_label = FALSE, denote = c("\n(", ")") ) qrcode_make(Labels, ErrCorr) code_128_make(Labels) code_128_make2(Labels)
custom_create_PDF( user = FALSE, Labels = NULL, name = "LabelsOut", type = "matrix", ErrCorr = "H", Fsz = 12, Across = TRUE, ERows = 0, ECols = 0, trunc = TRUE, numrow = 20, numcol = 4, page_width = 8.5, page_height = 11, width_margin = 0.25, height_margin = 0.5, label_width = NA, label_height = NA, x_space = 0, y_space = 0.5, alt_text = NULL, replace_label = FALSE, denote = c("\n(", ")") ) qrcode_make(Labels, ErrCorr) code_128_make(Labels) code_128_make2(Labels)
user |
logical. Run function using interactive mode (prompts user for
parameter values) Default is |
Labels |
vector or data frame object containing label names (i.e. unique ID codes) with either UTF-8 or ASCII encoding. |
name |
character. Name of the PDF output file. Default is
|
type |
character. Choice of |
ErrCorr |
error correction value for matrix labels only. Level of damage
from low to high: |
Fsz |
numerical. Sets font size in points. Longer ID codes may be shrunk
to fit if truncation is not used for matrix labels. Default font size is
|
Across |
logical. When |
ERows |
number of rows to skip. Default is |
ECols |
number of columns to skip. Default is |
trunc |
logical. Text is broken into multiple lines for longer ID codes,
to prevent printing off of the label area. Default is |
numrow |
numerical. Number of rows per page. Default is |
numcol |
numerical. Number of columns per page. Default is |
page_width |
numerical. Width of page (in inches). Default is set to
|
page_height |
numerical. Height of page (in inches). Default is set to
|
width_margin |
numerical. The width margin of the page (in inches).
Default is |
height_margin |
numerical. The height margin of the page (in inches).
Default is |
label_width |
numerical. The width of label (in inches). Will be
calculated as |
label_height |
numerical. The height of the label (in inches). Will be
calculated as |
x_space |
numerical. A value between |
y_space |
numerical. The height position of the text on the physical
label as a proportion of the label height. Only applies when |
alt_text |
vector containing alternative names that are printed along with Labels BUT ARE NOT ENCODED in the barcode image. Use with caution! |
replace_label |
logical. Replace label text with |
denote |
character (prefix) or vector of length 2 (prefix, suffix). Denotes alt_text that is not encoded in the barcode image. Default is brackets before and after (). |
qrcode_make
is the helper function for generating a QR code matrix.
code_128_make
is the helper function for generating a linear barcode
according to code 128 set B. code_128_make2
is the extended helper function for generating a linear barcode
according to code 128 set B, all Latin-1 characters, set C and partially A. custom_create_PDF
is the main function
which sets page layout, and creates the PDF file.
Correction levels for QR codes refer to the level of damage a label can tolerate before the label become unreadable by a scanner (L = Low (7%), M = Medium (15%), Q = Quantile (25%), H = High (30%)). So a label with L correction can lose up to at most 7 while a H label can lose up to 30 can be printed at smaller sizes compared to H codes.
The escape characters \n
and \s
(and the hex equivalents
\x0A
and \x20
can be used to format text labels. Tab character
\t
(\x09
) does not work for QR codes and should be replaced by
a number of space characters. See the package vignette for examples.
If ECol
or ERow
is greater than numcol
and numrow
,
the labels will be printed starting on the second page.
a PDF file containing QR-coded labels, saved to the default directory.
## this is the same examples used with create_PDF ## data frame example_vector <- as.data.frame(c("ao1", "a02", "a03")) ## Not run: ## run with default options ## pdf file will be "example.pdf" saved into a temp directory temp_file <- tempfile() custom_create_PDF(Labels = example_vector, name = temp_file) ## view example output from temp folder system2("open", paste0(temp_file, ".pdf")) ## End(Not run) ## run interactively. Overrides default pdf options if(interactive()){ custom_create_PDF(user = TRUE, Labels = example_vector) } ## Not run: ## run using a data frame, automatically choosing the "label" column example_df <- data.frame("level1" = c("a1", "a2"), "label" = c("a1-b1", "a1-b2"), "level2" = c("b1", "b1")) custom_create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_2")) ## End(Not run) ## Not run: ## run using an unnamed data frame example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame custom_create_PDF(user = FALSE, Labels = example_df[,2], name = file.path(tempdir(), "example_3")) ## End(Not run) ## Not run: ## create linear (code128) label rather than matrix (2D/QR) labels example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame custom_create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_4", type = "linear")) ## End(Not run) ## Not run: ## Include text for the user that is NOT encoded into the barcode image ## Excluded text is denoted with brackets by default example_df <- data.frame(ID = floor(runif(3) * 10000), name = c("A", "B", "C"), dob = c("1/1/2020", "12/6/2001", "2/8/1986")) ## linear (1d) barcodes with custom denote parameter custom_create_PDF(Labels = example_df$ID, alt_text = paste(example_df$name, example_df$dob), type = "linear", denote=".") ## End(Not run)
## this is the same examples used with create_PDF ## data frame example_vector <- as.data.frame(c("ao1", "a02", "a03")) ## Not run: ## run with default options ## pdf file will be "example.pdf" saved into a temp directory temp_file <- tempfile() custom_create_PDF(Labels = example_vector, name = temp_file) ## view example output from temp folder system2("open", paste0(temp_file, ".pdf")) ## End(Not run) ## run interactively. Overrides default pdf options if(interactive()){ custom_create_PDF(user = TRUE, Labels = example_vector) } ## Not run: ## run using a data frame, automatically choosing the "label" column example_df <- data.frame("level1" = c("a1", "a2"), "label" = c("a1-b1", "a1-b2"), "level2" = c("b1", "b1")) custom_create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_2")) ## End(Not run) ## Not run: ## run using an unnamed data frame example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame custom_create_PDF(user = FALSE, Labels = example_df[,2], name = file.path(tempdir(), "example_3")) ## End(Not run) ## Not run: ## create linear (code128) label rather than matrix (2D/QR) labels example_df <- data.frame(c("a1", "a2"), c("a1-b1", "a1-b2"), c("b1", "b1")) ## specify column from data frame custom_create_PDF(user = FALSE, Labels = example_df, name = file.path(tempdir(), "example_4", type = "linear")) ## End(Not run) ## Not run: ## Include text for the user that is NOT encoded into the barcode image ## Excluded text is denoted with brackets by default example_df <- data.frame(ID = floor(runif(3) * 10000), name = c("A", "B", "C"), dob = c("1/1/2020", "12/6/2001", "2/8/1986")) ## linear (1d) barcodes with custom denote parameter custom_create_PDF(Labels = example_df$ID, alt_text = paste(example_df$name, example_df$dob), type = "linear", denote=".") ## End(Not run)
This addin will allow you to interactive create ID codes and generate PDF files of QR codes.
make_labels()
make_labels()
Opens RStudio addin gadget window for making labels and barcodes in a GUI
if(interactive()){ library(baRcodeR) make_labels() }
if(interactive()){ library(baRcodeR) make_labels() }
Generate hierarchical ID codes for barcode labels.
Hierarchical codes have a nested structure: e.g. Y subsamples from
each of X individuals. Use uniqID_maker
for sequential single-level labels. Can be run in interactive mode,
prompting user for input. The data.frame can be saved as CSV for
(i) the create_PDF
function to generate printable
QR-coded labels; and (ii) to downstream data collection using spreadsheet,
relational database, etc.
uniqID_hier_maker(user = FALSE, hierarchy, end = NULL, digits = 2)
uniqID_hier_maker(user = FALSE, hierarchy, end = NULL, digits = 2)
user |
logical. Run function using interactive mode (prompts user for
parameter values). Default is |
hierarchy |
list. A list with each element consisting of three members
a vector of three elements (string, beginning value, end value). See examples.
Used only when |
end |
character. A string to be appended to the end of each label. |
digits |
numerical. Default is |
data.frame of text labels in the first column, with additional columns for each level in the hierarchy list, as defined by the user.
if(interactive()){ ## for interactive mode uniqID_hier_maker(user = TRUE) } ## how to make hierarchy list ## create vectors for each level in the order string_prefix, beginning_value, ## end_value and combine in list a <- c("a", 3, 6) b <- c("b", 1, 3) c <- list(a, b) Labels <- uniqID_hier_maker(hierarchy = c) Labels ## add string at end of each label Labels <- uniqID_hier_maker(hierarchy = c, end = "end") Labels
if(interactive()){ ## for interactive mode uniqID_hier_maker(user = TRUE) } ## how to make hierarchy list ## create vectors for each level in the order string_prefix, beginning_value, ## end_value and combine in list a <- c("a", 3, 6) b <- c("b", 1, 3) c <- list(a, b) Labels <- uniqID_hier_maker(hierarchy = c) Labels ## add string at end of each label Labels <- uniqID_hier_maker(hierarchy = c, end = "end") Labels
Create ID codes consisting of a text string and unique numbers (string001, string002, ...).
Can be run in interactive mode, prompting user for input. The data.frame
output can be saved as CSV for (i) the create_PDF
function
to generate printable QR-coded labels; and (ii) to downstream data
collection software (spreadsheets, relational databases, etc.)
uniqID_maker( user = FALSE, string = NULL, level, digits = 3, ending_string = NULL )
uniqID_maker( user = FALSE, string = NULL, level, digits = 3, ending_string = NULL )
user |
logical. Run function using interactive mode (prompts user for
parameter values). Default is |
string |
character. Text string for label. Default |
level |
integer vector. Defines the numerical values to be appended to the character string. Can be any sequence of numbers (see examples). |
digits |
numerical. Default is |
ending_string |
a character string or vector of strings to attach to the label. If a vector is used, all combinations of that vector with a unique label will be produced. |
When the function is called with user = TRUE
, a sequence of
numbers is generated between the starting and ending number provided by the
user. When user = FALSE
, a vector of custom numbers can be provided.
See example below.
data.frame with text labels in the first column, along with string and numeric values in two additional columns.
## sequential string of numbers in label Labels <- uniqID_maker(string = "string", level = c(1:5), digits = 2) Labels ## can also use nonsequential strings in input for levels level <- c(1:5, 8:10, 999:1000) Labels <- uniqID_maker(string = "string", level = level, digits = 4) Labels ## Using the ending_string to produce labels with unique endings ## this is different from hierarchical labels with two levels as there ## is no numbering, just the text string Labels <- uniqID_maker(string = "string", level = c(1:5), digits = 2, ending_string = "A") Labels Labels <- uniqID_maker(string = "string", level = c(1:5), digits = 2, ending_string = c("A", "B")) Labels if(interactive()){ ## function using user prompt does not use any of the other parameters Labels <- uniqID_maker(user = TRUE) Labels }
## sequential string of numbers in label Labels <- uniqID_maker(string = "string", level = c(1:5), digits = 2) Labels ## can also use nonsequential strings in input for levels level <- c(1:5, 8:10, 999:1000) Labels <- uniqID_maker(string = "string", level = level, digits = 4) Labels ## Using the ending_string to produce labels with unique endings ## this is different from hierarchical labels with two levels as there ## is no numbering, just the text string Labels <- uniqID_maker(string = "string", level = c(1:5), digits = 2, ending_string = "A") Labels Labels <- uniqID_maker(string = "string", level = c(1:5), digits = 2, ending_string = c("A", "B")) Labels if(interactive()){ ## function using user prompt does not use any of the other parameters Labels <- uniqID_maker(user = TRUE) Labels }