Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorization work on clean_contents; Roxygen 6.1.0 build #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,9 @@ S3method("$<-",huxtable)
S3method("[",huxtable)
S3method("[<-",huxtable)
S3method("[[<-",huxtable)
S3method("align<-", huxtable)
S3method("background_color<-", huxtable)
S3method("bold<-", huxtable)
S3method("bottom_border<-", huxtable)
S3method("bottom_border_color<-", huxtable)
S3method("bottom_border_style<-", huxtable)
S3method("bottom_padding<-", huxtable)
S3method("caption<-", huxtable)
S3method("caption_pos<-", huxtable)
S3method("col_width<-", huxtable)
S3method("colspan<-", huxtable)
S3method("dimnames<-",huxtable)
S3method("escape_contents<-", huxtable)
S3method("font<-", huxtable)
S3method("font_size<-", huxtable)
S3method("height<-", huxtable)
S3method("italic<-", huxtable)
S3method("label<-", huxtable)
S3method("latex_float<-", huxtable)
S3method("left_border<-", huxtable)
S3method("left_border_color<-", huxtable)
S3method("left_border_style<-", huxtable)
S3method("left_padding<-", huxtable)
S3method("na_string<-", huxtable)
S3method("number_format<-", huxtable)
S3method("pad_decimal<-", huxtable)
S3method("position<-", huxtable)
S3method("right_border<-", huxtable)
S3method("right_border_color<-", huxtable)
S3method("right_border_style<-", huxtable)
S3method("right_padding<-", huxtable)
S3method("rotation<-", huxtable)
S3method("row_height<-", huxtable)
S3method("rowspan<-", huxtable)
S3method("tabular_environment<-", huxtable)
S3method("text_color<-", huxtable)
S3method("top_border<-", huxtable)
S3method("top_border_color<-", huxtable)
S3method("top_border_style<-", huxtable)
S3method("top_padding<-", huxtable)
S3method("valign<-", huxtable)
S3method("width<-", huxtable)
S3method("wrap<-", huxtable)
S3method(add_colnames,huxtable)
S3method(add_rownames,huxtable)
S3method(align, huxtable)
S3method(as_Workbook,huxtable)
S3method(as_flextable,huxtable)
S3method(as_huxtable,character)
Expand All @@ -60,56 +17,15 @@ S3method(as_huxtable,huxtable)
S3method(as_huxtable,logical)
S3method(as_huxtable,numeric)
S3method(as_huxtable,table)
S3method(background_color, huxtable)
S3method(bold, huxtable)
S3method(bottom_border, huxtable)
S3method(bottom_border_color, huxtable)
S3method(bottom_border_style, huxtable)
S3method(bottom_padding, huxtable)
S3method(caption, huxtable)
S3method(caption_pos, huxtable)
S3method(cbind,huxtable)
S3method(col_width, huxtable)
S3method(colspan, huxtable)
S3method(escape_contents, huxtable)
S3method(font, huxtable)
S3method(font_size, huxtable)
S3method(format,huxtable)
S3method(height, huxtable)
S3method(italic, huxtable)
S3method(label, huxtable)
S3method(latex_float, huxtable)
S3method(left_border, huxtable)
S3method(left_border_color, huxtable)
S3method(left_border_style, huxtable)
S3method(left_padding, huxtable)
S3method(na_string, huxtable)
S3method(number_format, huxtable)
S3method(pad_decimal, huxtable)
S3method(position, huxtable)
S3method(print,huxtable)
S3method(rbind,huxtable)
S3method(right_border, huxtable)
S3method(right_border_color, huxtable)
S3method(right_border_style, huxtable)
S3method(right_padding, huxtable)
S3method(rotation, huxtable)
S3method(row_height, huxtable)
S3method(rowspan, huxtable)
S3method(t,huxtable)
S3method(tabular_environment, huxtable)
S3method(text_color, huxtable)
S3method(to_html,huxtable)
S3method(to_latex,huxtable)
S3method(to_md,huxtable)
S3method(to_screen,huxtable)
S3method(top_border, huxtable)
S3method(top_border_color, huxtable)
S3method(top_border_style, huxtable)
S3method(top_padding, huxtable)
S3method(valign, huxtable)
S3method(width, huxtable)
S3method(wrap, huxtable)
export("align<-")
export("background_color<-")
export("bold<-")
Expand Down
28 changes: 15 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,31 @@ assert_package <- function (fun, package) {
# return character matrix of formatted contents, suitably escaped
clean_contents <- function(ht, type = c('latex', 'html', 'screen', 'markdown', 'word', 'excel'), ...) {
type <- match.arg(type)
contents <- as.matrix(as.data.frame(ht))
contents <- as.matrix(as.data.frame(ht), mode = 'character')

for (col in seq_len(ncol(contents))) {
for (row in seq_len(nrow(contents))) {
cell <- contents[row, col]
num_fmt <- number_format(ht)[[row, col]] # a list element, double brackets
if (! is.na(cell)) cell <- format_numbers(cell, num_fmt)
if (is.na(cell)) cell <- na_string(ht)[row, col]
cell <- format_numbers(cell, num_fmt)
contents[row, col] <- as.character(cell)
}
if (type %in% c('latex', 'html')) {
to_esc <- escape_contents(ht)[, col]
contents[to_esc, col] <- sanitize(contents[to_esc, col], type)
}
# has to be after sanitization because we add &nbsp; for HTML (and non-space stuff for LaTeX):
# later we can just use align for this:
pad_chars <- pad_decimal(ht)[, col]
}
contents[is.na(contents)] <- na_string(ht)

if (type %in% c('latex', 'html')) {
to_esc <- escape_contents(ht)
contents[to_esc, ] <- sanitize(contents[to_esc, ], type)
}
# has to be after sanitization because we add &nbsp; for HTML (and non-space stuff for LaTeX):
# later we can just use align for this:

pad_chars <- pad_decimal(ht)
for (col in seq_len(ncol(contents))) {
align_pad <- ncharw(align(ht)[, col]) == 1
pad_chars[align_pad] <- align(ht)[align_pad, col]
contents[, col] <- decimal_pad(contents[, col], pad_chars, type)
}

contents
decimal_pad(contents, pad_chars, type)
}


Expand Down
2 changes: 1 addition & 1 deletion man/align.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_flextable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/as_huxtable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/background_color.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/bold.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/caption.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/caption_pos.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions man/cbind.huxtable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/col_width.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/escape_contents.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/font.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/font_size.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/height.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/huxreg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions man/huxtable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/knit_print.data.frame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/knit_print.huxtable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/label.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/latex_float.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading