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

Add dt_*() methods for all major, internal data structures #355

Merged
merged 103 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
bfd7131
Add `dt_*()` util fcns
rich-iannone Aug 14, 2019
f9f0b92
Initialize internal objects with `dt_*()` fcns
rich-iannone Aug 14, 2019
40db1de
Refactor `dt_boxh_edit()` util fcn
rich-iannone Aug 15, 2019
cc22b4c
Modify the `dt_spanners_add()` util fcn
rich-iannone Aug 15, 2019
b93a6d1
Use leading period for global object
rich-iannone Aug 15, 2019
0cbd1bc
Add the `dt_boxh_get_vars()` util fcn
rich-iannone Aug 15, 2019
7eb92ac
Add comment
rich-iannone Aug 15, 2019
21183be
Rewrite the `cols_split_delim()` fcn
rich-iannone Aug 15, 2019
00a3d1a
Update help file using roxygen
rich-iannone Aug 15, 2019
20b2f93
Create and use `dt_*()` fcns
rich-iannone Aug 30, 2019
106e1cc
Merge branch 'master' into dt_boxh
rich-iannone Aug 30, 2019
ac99bca
Add several `dt_*()` functions
rich-iannone Sep 3, 2019
c3db2db
Update help files using roxygen
rich-iannone Sep 3, 2019
bea6a83
Update vignette
rich-iannone Sep 3, 2019
ffbb335
Remove function call
rich-iannone Sep 3, 2019
af2f650
Update vignette
rich-iannone Sep 3, 2019
a8e5c4a
Add several `dt_*()` methods
rich-iannone Sep 4, 2019
ce9ed80
Modify `dt_*()` fcns
rich-iannone Sep 4, 2019
f43d4b1
Modify several `dt_*()` fcns
rich-iannone Sep 4, 2019
7e18530
Make several corrections
rich-iannone Sep 4, 2019
2ea4130
Remove commented code
rich-iannone Sep 4, 2019
0db4d76
Update several tests
rich-iannone Sep 4, 2019
bda2ef2
Create methods for arranging row groups
rich-iannone Sep 4, 2019
bdc010f
Remove commented code
rich-iannone Sep 4, 2019
90d528e
Remove unneeded function
rich-iannone Sep 4, 2019
2a199ca
Remove unneeded function call
rich-iannone Sep 4, 2019
7024372
Add comments
rich-iannone Sep 4, 2019
cc52ede
Update documentation
rich-iannone Sep 5, 2019
0acfd21
Improve `dt_transforms*()` fcns
rich-iannone Sep 5, 2019
4567d2d
Remove unneeded statements
rich-iannone Sep 5, 2019
4b631d6
Makes changes based on fcn name change
rich-iannone Sep 5, 2019
f1a0be7
Rename SVG file
rich-iannone Sep 6, 2019
8136286
Add option to `dt_spanners_print()`
rich-iannone Sep 6, 2019
0be784b
Use all arg names when calling fcn
rich-iannone Sep 6, 2019
3478f99
Make corrections to `reorder_footnotes()`
rich-iannone Sep 6, 2019
2960aeb
Rewrite several LaTeX rendering fcns
rich-iannone Sep 6, 2019
b675470
Remove linebreak
rich-iannone Sep 6, 2019
136a7be
Add linebreaks
rich-iannone Sep 6, 2019
77d7c83
Make corrections to `as_latex()` fcn
rich-iannone Sep 6, 2019
bcdcce9
Ensure that footnotes for spanners are correct
rich-iannone Sep 6, 2019
5fcb2de
Make corrections to tests
rich-iannone Sep 6, 2019
516370a
Make a correction to a test
rich-iannone Sep 6, 2019
0d94ba2
Add a TODO
rich-iannone Sep 6, 2019
371eac8
Remove commented code
rich-iannone Sep 6, 2019
652b215
Restore RTF rendering support
rich-iannone Sep 6, 2019
39bffdc
Update roxygen documentation
rich-iannone Sep 6, 2019
3b1c16f
Update help file using roxygen
rich-iannone Sep 6, 2019
9b61a0b
Update .gitignore
rich-iannone Sep 6, 2019
926d3dc
Update as_rtf.R
rich-iannone Sep 6, 2019
997df68
Modify defaults in `cols_merge()`
rich-iannone Sep 6, 2019
d0053cf
Update resolver.R
rich-iannone Sep 6, 2019
ca16160
Update text_transform.R
rich-iannone Sep 6, 2019
db11ccd
Update location_methods.R
rich-iannone Sep 6, 2019
13e421a
Modify defaults for `cells_*()` fcns
rich-iannone Sep 6, 2019
9fa9ca3
Update utils_render_footnotes.R
rich-iannone Sep 6, 2019
5e9fca8
Update help files using roxygen
rich-iannone Sep 6, 2019
44179f0
Upgrade the `dt_arrange_groups_*()` fcns
rich-iannone Sep 6, 2019
61eb2df
Remove commented code
rich-iannone Sep 6, 2019
e60b349
Refactor function
rich-iannone Sep 6, 2019
3cd0c03
Add init method for transforms in `gt()`
rich-iannone Sep 6, 2019
0fcb70b
Update several testthat tests
rich-iannone Sep 6, 2019
8ce58f0
Remove some HTML-specific formatting in dates/times
rich-iannone Sep 7, 2019
ade4c78
Migrate `stub_df` to unified object
rich-iannone Sep 10, 2019
7e41997
Split objects into separate `dt_*()` methods
rich-iannone Sep 11, 2019
d9ee16c
Refactor summary-based methods
rich-iannone Sep 12, 2019
8cf1233
Create separate column label / spanner locations
rich-iannone Sep 13, 2019
aba37c0
Update html-13-adding_footnotes.R
rich-iannone Sep 13, 2019
8ea0006
Update help file using roxygen
rich-iannone Sep 13, 2019
c3ce5fd
Update roxygen @examples section
rich-iannone Sep 13, 2019
1a8dbaf
Update html-13-adding_footnotes.R
rich-iannone Sep 13, 2019
8a079cf
Rename some internal object names
rich-iannone Sep 13, 2019
c0fbbb2
Move all location fcns to the same .R file
rich-iannone Sep 13, 2019
78b54ba
Replace `missing()` with `is.null()`
rich-iannone Sep 13, 2019
89c2c35
Replace `seq()` with `seq_along()`
rich-iannone Sep 13, 2019
9c13f0a
Remove unneeded internal functions
rich-iannone Sep 13, 2019
4aafdde
correct usage of `get_groups_rows_df()`
rich-iannone Sep 13, 2019
d6de4a9
Update .Rbuildignore
rich-iannone Sep 13, 2019
3f7bf94
Create `dt_stub_components()` fcn
rich-iannone Sep 13, 2019
7af7c0d
Apply class using `class()` (not `attr()`)
rich-iannone Sep 13, 2019
55db36d
Remove extra col alignment fcns
rich-iannone Sep 13, 2019
2015a0b
Refactor the building of the output table
rich-iannone Sep 13, 2019
a646daf
Prefix `n()` function in roxygen examples
rich-iannone Sep 13, 2019
f258394
Merge branch 'master' into dt_boxh
rich-iannone Sep 13, 2019
d279f9b
Refactor `dt_summary_build()`
rich-iannone Sep 26, 2019
cc54e80
Update test-gtsave.R
rich-iannone Sep 26, 2019
9aea2a6
Refactor `dt_summary_df*()` fcns
rich-iannone Sep 26, 2019
60c3bd4
Refactor `dt_summary_build()` fcn
rich-iannone Sep 27, 2019
cab7621
Fix spelling errors
rich-iannone Sep 27, 2019
fada05e
Do not unique and sort column indices
rich-iannone Sep 27, 2019
a54eab5
Have `resolve_cells_data()` return column names
rich-iannone Sep 27, 2019
12665ea
Formatting summary data should use gt structure
rich-iannone Sep 27, 2019
6125268
Remove uses of `as.data.frame()`
rich-iannone Sep 27, 2019
660365d
Correct partial arg in call
rich-iannone Sep 27, 2019
89fa652
Use the `dt_data_get()` fcn in tests
rich-iannone Sep 27, 2019
946d70e
Change gt structure to be a list object
rich-iannone Sep 27, 2019
a93e27b
Make corrections to vignette
rich-iannone Sep 27, 2019
a9112b8
Add `dt__get()` and `dt__set()` fcns
rich-iannone Sep 27, 2019
098f66c
Replace use of `attr()` with get and set fcns
rich-iannone Sep 27, 2019
443c7d6
Make corrections to several testthat tests
rich-iannone Sep 27, 2019
09fac76
Remove `rowname` col from dt_body
rich-iannone Sep 27, 2019
674ec14
Add `as.data.frame()` for formatted gt object
rich-iannone Sep 27, 2019
e16027e
Update TODOS.R
rich-iannone Sep 27, 2019
9ba300a
Remove TODO comment
rich-iannone Oct 4, 2019
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tests/examples
tests/manual_tests
^vignettes/videos$
^vignettes/images/apng$
^TODOS
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ vignettes/*.pdf

# Other files
.DS_Store
test.rtf
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(as.data.frame,gt_tbl)
S3method(print,gt_tbl)
export("%>%")
export(adjust_luminance)
Expand All @@ -10,6 +11,7 @@ export(cell_borders)
export(cell_fill)
export(cell_text)
export(cells_column_labels)
export(cells_column_spanners)
export(cells_data)
export(cells_grand_summary)
export(cells_group)
Expand All @@ -27,7 +29,6 @@ export(cols_merge_uncert)
export(cols_move)
export(cols_move_to_end)
export(cols_move_to_start)
export(cols_split_delim)
export(cols_width)
export(contains)
export(currency)
Expand Down Expand Up @@ -78,6 +79,7 @@ export(tab_options)
export(tab_row_group)
export(tab_source_note)
export(tab_spanner)
export(tab_spanner_delim)
export(tab_stubhead)
export(tab_style)
export(test_image)
Expand Down
30 changes: 30 additions & 0 deletions R/as_data_frame.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' @export
as.data.frame.gt_tbl <- function(x, ...) {

data <- x

data_built <-
data %>%
build_data(context = "html")

ret <-
data_built %>%
dt_body_get() %>%
as.data.frame(stringsAsFactors = FALSE)

has_rowname <-
data_built %>%
dt_stub_components() %>%
dt_stub_components_has_rowname()

if (has_rowname) {
rowname_vals <-
data_built %>%
dt_stub_df_get() %>%
dplyr::pull(rowname)

rownames(ret) <- rowname_vals
}

ret
}
149 changes: 37 additions & 112 deletions R/as_latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,128 +37,53 @@
as_latex <- function(data) {

# Build all table data objects through a common pipeline
built_data <- data %>% build_data(context = "latex")
data <- data %>% build_data(context = "latex")

# Use LaTeX-specific builders to generate the Latex table code
with(built_data, {
# Composition of LaTeX ----------------------------------------------------

# Add footnote marks to elements of the table columns
boxh_df <-
set_footnote_marks_columns(
footnotes_resolved = footnotes_resolved,
boxh_df = boxh_df,
output = "latex"
)
# Create a LaTeX fragment for the start of the table
table_start <- create_table_start_l(data = data)

# Add footnote marks to the `data` rows
output_df <-
apply_footnotes_to_output(
output_df = output_df,
footnotes_resolved = footnotes_resolved,
output = "latex"
)
# Create the heading component
heading_component <- create_heading_component(data = data, context = "latex")

# Add footnote marks to stub group title elements
groups_rows_df <-
set_footnote_marks_stub_groups(
footnotes_resolved = footnotes_resolved,
groups_rows_df = groups_rows_df,
output = "latex"
)
# Create the columns component
columns_component <- create_columns_component_l(data = data)

# Add footnote marks to the `summary` rows
list_of_summaries <-
apply_footnotes_to_summary(
list_of_summaries = list_of_summaries,
footnotes_resolved = footnotes_resolved
)
# Create the body component
body_component <- create_body_component_l(data = data)

# Extraction of body content as a vector ----------------------------------
body_content <- as.vector(t(output_df))
# Create the source notes component
source_notes_component <- create_source_note_component_l(data = data)

# Composition of LaTeX ----------------------------------------------------
# Create the footnotes component
footnotes_component <- create_footnotes_component_l(data = data)

# Split `body_content` by slices of rows
row_splits <- split(body_content, ceiling(seq_along(body_content) / n_cols))
# Create a LaTeX fragment for the ending tabular statement
table_end <- create_table_end_l()

# Create a LaTeX fragment for the start of the table
table_start <- create_table_start_l(col_alignment = col_alignment)
# If the `rmarkdown` package is available, use the
# `latex_dependency()` function to load latex packages
# without requiring the user to do so
if (requireNamespace("rmarkdown", quietly = TRUE)) {

# Create the heading component of the table
heading_component <-
create_heading_component(
heading = heading,
footnotes_resolved = footnotes_resolved,
styles_resolved = styles_resolved,
n_cols = n_cols,
subtitle_defined = subtitle_defined,
output = "latex"
)
latex_packages <-
lapply(latex_packages(), rmarkdown::latex_dependency)

# Create the columns component of the table
columns_component <-
create_columns_component_l(
boxh_df = boxh_df,
output_df = output_df,
stub_available = stub_available,
spanners_present = spanners_present,
stubhead = stubhead
)
} else {
latex_packages <- NULL
}

# Create the body component of the table
body_component <-
create_body_component_l(
row_splits = row_splits,
groups_rows_df = groups_rows_df,
col_alignment = col_alignment,
stub_available = stub_available,
summaries_present = summaries_present,
list_of_summaries = list_of_summaries,
n_rows = n_rows,
n_cols = n_cols
)

# Create a LaTeX fragment for the ending tabular statement
table_end <- create_table_end_l()

# Create the footnote component of the table
footnote_component <-
create_footnote_component_l(
footnotes_resolved = footnotes_resolved,
opts_df = opts_df
)

# Create the source note component of the table
source_note_component <-
create_source_note_component_l(
source_note = source_note
)

# If the `rmarkdown` package is available, use the
# `latex_dependency()` function to load latex packages
# without requiring the user to do so
if (requireNamespace("rmarkdown", quietly = TRUE)) {

latex_packages <-
lapply(latex_packages(), rmarkdown::latex_dependency)

} else {
latex_packages <- NULL
}

# Compose the LaTeX table
latex_table <-
paste0(
table_start,
heading_component,
columns_component,
body_component,
table_end,
footnote_component,
source_note_component,
collapse = "") %>%
knitr::asis_output(meta = latex_packages)

latex_table
})
# Compose the LaTeX table
paste0(
table_start,
heading_component,
columns_component,
body_component,
table_end,
footnotes_component,
source_notes_component,
collapse = ""
) %>%
knitr::asis_output(meta = latex_packages)
}
Loading