Skip to content
Merged
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
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rmarkdown
Type: Package
Title: Dynamic Documents for R
Version: 1.1.9012
Version: 1.1.9013
Authors@R: c(
person("JJ", "Allaire", role = c("aut", "cre"), email = "jj@rstudio.com"),
person("Joe", "Cheng", role = "aut", email = "joe@rstudio.com"),
Expand Down Expand Up @@ -69,13 +69,14 @@ Imports:
evaluate (>= 0.8),
base64enc,
jsonlite,
tibble,
rprojroot
rprojroot,
methods
Suggests:
shiny (>= 0.11),
tufte,
testthat,
digest
digest,
tibble
SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org
URL: http://rmarkdown.rstudio.com
License: GPL-3
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ export(tufte_handout)
export(word_document)
export(yaml_front_matter)
import(htmltools)
import(methods)
import(rprojroot)
import(tibble)
importFrom(evaluate,evaluate)
1 change: 0 additions & 1 deletion R/html_notebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' \code{html_notebook}, see \href{http://rmarkdown.rstudio.com/r_notebook_format.html}{http://rmarkdown.rstudio.com/r_notebook_format.html}.
#'
#' @importFrom evaluate evaluate
#' @import tibble
#' @export
html_notebook <- function(toc = FALSE,
toc_depth = 3,
Expand Down
92 changes: 90 additions & 2 deletions R/html_paged.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
# paged_table_type_sum and paged_table_obj_sum should be replaced
# by tibble::type_sum once tibble supports R 3.0.0.
paged_table_type_sum <- function(x) {
type_sum <- function(x)
{
format_sum <- switch (class(x)[[1]],
ordered = "ord",
factor = "fctr",
POSIXt = "dttm",
difftime = "time",
Date = date,
data.frame = class(x)[[1]],
tbl_df = "tibble",
NULL
)
if (!is.null(format_sum)) {
format_sum
} else if (!is.object(x)) {
switch(typeof(x),
logical = "lgl",
integer = "int",
double = "dbl",
character = "chr",
complex = "cplx",
closure = "fun",
environment = "env",
typeof(x)
)
} else if (!isS4(x)) {
paste0("S3: ", class(x)[[1]])
} else {
paste0("S4: ", methods::is(x)[[1]])
}
}

type_sum(x)
}

paged_table_obj_sum <- function(x) {
"%||%" <- function(x, y) {
if(is.null(x)) y else x
}

big_mark <- function(x, ...) {
mark <- if (identical(getOption("OutDec"), ",")) "." else ","
formatC(x, big.mark = mark, ...)
}

dim_desc <- function(x) {
dim <- dim(x) %||% length(x)
format_dim <- vapply(dim, big_mark, character(1))
format_dim[is.na(dim)] <- "??"
paste0(format_dim, collapse = " \u00d7 ")
}

is_atomic <- function(x) {
is.atomic(x) && !is.null(x)
}

is_vector <- function(x) {
is_atomic(x) || is.list(x)
}

paged_table_is_vector_s3 <- function(x) {
switch(class(x)[[1]],
ordered = TRUE,
factor = TRUE,
Date = TRUE,
POSIXct = TRUE,
difftime = TRUE,
data.frame = TRUE,
!is.object(x) && is_vector(x))
}

size_sum <- function(x) {
if (!paged_table_is_vector_s3(x)) return("")

paste0(" [", dim_desc(x), "]" )
}

switch(class(x)[[1]],
POSIXlt = rep("POSIXlt", length(x)),
list = vapply(x, paged_table_obj_sum, character(1L)),
paste0(paged_table_type_sum(x), size_sum(x))
)
}

#' @import methods
paged_table_html <- function(x) {
addRowNames = .row_names_info(data, type = 1) > 0

Expand All @@ -18,7 +106,7 @@ paged_table_html <- function(x) {
function(columnIdx) {
column <- data[[columnIdx]]
baseType <- class(column)[[1]]
tibbleType <- tibble::type_sum(column)
tibbleType <- paged_table_type_sum(column)

list(
label = if (!is.null(columnNames)) columnNames[[columnIdx]] else "",
Expand Down Expand Up @@ -51,7 +139,7 @@ paged_table_html <- function(x) {

is_list <- vapply(data, is.list, logical(1))
data[is_list] <- lapply(data[is_list], function(x) {
summary <- tibble::obj_sum(x)
summary <- paged_table_obj_sum(x)
paste0("<", summary, ">")
})

Expand Down
6 changes: 5 additions & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,12 @@ resolve_df_print <- function(df_print) {
if (!is.function(df_print)) {
if (df_print == "kable")
df_print <- knitr::kable
else if (df_print == "tibble")
else if (df_print == "tibble") {
if (!requireNamespace("tibble", quietly = TRUE))
stop("Printing 'tibble' without 'tibble' package available")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if instead of making this a hard error we could just use the default print method (and maybe warn once per session)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinushey how do we usually warn once per session? By setting a global or there is a nicer way for doing this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slightly cleaner implementation would be with a factory function e.g.

make_warning <- function(message) {
    message <- message
    warned <- FALSE
    function() {
        if (warned) return()
        warning(message)
        warned <<- TRUE
    }
}

tibble_warning <- make_warning("...")
tibble_warning()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think that if they ask for tibble and we can't provide it then we are just fine to error (I think this will be a very narrow case as tibble is installed with dplyr and won't be a common choice given that pagedtable is available).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept as is.


df_print <- function(x) print(tibble::as_tibble(x))
}
else if (df_print == "paged")
df_print <- function(x) knitr::asis_output(paged_table_html(x))
else if (df_print == "default")
Expand Down
4 changes: 2 additions & 2 deletions man/shiny_prerendered_server_start_code.Rd

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