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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DT
Type: Package
Title: A Wrapper of the JavaScript Library 'DataTables'
Version: 0.13.1
Version: 0.13.2
Authors@R: c(
person("Yihui", "Xie", email = "[email protected]", role = c("aut", "cre")),
person("Joe", "Cheng", role = "aut"),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGES IN DT VERSION 0.14

## MINOR CHANGES

- The formatting functions now throw clearer error messages when called on non-datatables objects (thanks, @shrektan, #785).

# CHANGES IN DT VERSION 0.13

Expand Down
4 changes: 4 additions & 0 deletions R/format.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
formatColumns = function(table, columns, template, ..., appendTo = c('columnDefs', 'rowCallback')) {
if (!inherits(table, 'datatables'))
stop("Invalid table argument; a table object created from datatable() was expected")
if (inherits(columns, 'formula')) columns = all.vars(columns)
x = table$x
colnames = base::attr(x, 'colnames', exact = TRUE)
Expand Down Expand Up @@ -114,6 +116,8 @@ formatSignif = function(
#' \code{params = list('ko-KR', list(year = 'numeric', month = 'long', day =
#' 'numeric'))}
formatDate = function(table, columns, method = 'toDateString', params = NULL) {
if (!inherits(table, 'datatables'))
stop("Invalid table argument; a table object created from datatable() was expected")
x = table$x
if (x$filter != 'none') {
if (inherits(columns, 'formula')) columns = all.vars(columns)
Expand Down
13 changes: 13 additions & 0 deletions tests/testit/test-format.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(testit)

# fix issue #785
assert("formatXXX() should throw clear errors when table is not valid", {
# The implementation of formatDate is a little different from other formatting functions
# So we test both of them
has_error(formatDate(list(x = 1L)), silent = TRUE)
has_error(formatCurrency(list(x = 1L)), silent = TRUE)
out = try(formatDate(list(x = 1L)), silent = TRUE)
(grepl("Invalid table", as.character(out), fixed = TRUE))
out = try(formatCurrency(list(x = 1L)), silent = TRUE)
(grepl("Invalid table", as.character(out), fixed = TRUE))
})