Skip to content

Commit 22ae924

Browse files
authored
predicate print_dispatch behavior on getOption("boxr.print_tibble") (#179)
* predicate print_dispatch behavior on getOption("boxr.print_tibble") * limit printing of data.frame to 10 rows * tweak NEWS item * bump version * add to boxr_options(), documentation. bump version
1 parent 90df3f8 commit 22ae924

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: boxr
22
Type: Package
33
Title: Interface for the 'Box.com API'
4-
Version: 0.3.5.9008
4+
Version: 0.3.5.9009
55
Authors@R: c(
66
person("Brendan", "Rocks", email = "[email protected]",
77
role = c("aut")),

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Improvements
44

5+
* Some return objects can be printed as tibble (vs. data-frame). To enable this behavior, set `options(boxr.print_tibble = TRUE)` (perhaps in your `.Rprofile`).
6+
57
* new tools to manage [collaborations](https://developer.box.com/reference/resources/collaboration/):
68
- `box_dir_invite()` is deprecated in favor of `box_collab_create()`.
79
- adds `box_collab_create()`, which supports file and group based collaborations.

R/boxr_misc.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ box_getwd <- function() {
213213
#' `id` `(numeric)`, and `name` `(character)`.}
214214
#' \item{`boxr.wd.path`}{`character`, path to the Box working-directory.}
215215
#' \item{`boxr.token`}{Object with S3 class `Token2.0` (`httr::Token2.0`).}
216+
#' \item{`boxr_token_jwt`}{Object with S3 class `request` (`httr::request`).}
217+
#' \item{`boxr.print_tibble`}{`logical`, indicates to print as tibble where available.}
216218
#' }
217219
#'
218220
#' @export
@@ -224,7 +226,8 @@ boxr_options <- function() {
224226
"boxr.verbose",
225227
"boxr.progress",
226228
"boxr.interactive",
227-
"boxr_token_jwt"
229+
"boxr_token_jwt",
230+
"boxr.print_tibble"
228231
)
229232

230233
o <- options()

R/boxr_s3_classes.R

+15-4
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,14 @@ print_df_summary <- function(file_list, msg_list) {
542542
dummy_var <- mapply(print_df, file_list, msg_list)
543543
}
544544

545-
546545
print_dispatch <- function(x, ...) {
547546

548-
if (requireNamespace("tibble", quietly = TRUE)) {
547+
has_tibble <- requireNamespace("tibble", quietly = TRUE)
548+
549+
# should this default TRUE or FALSE?
550+
print_tibble <- getOption("boxr.print_tibble") %||% FALSE
551+
552+
if (has_tibble && print_tibble) {
549553
print_using_tibble(x, ...)
550554
} else {
551555
print_using_df(x, ...)
@@ -555,14 +559,21 @@ print_dispatch <- function(x, ...) {
555559
}
556560

557561
print_using_df <- function(x, ...) {
562+
563+
has_tibble <- requireNamespace("tibble", quietly = TRUE)
558564

559565
df <- as.data.frame(x)
560566

561567
cat("--- printing as data.frame ---\n")
562-
print(df, ...)
568+
print(df, max = 10 * ncol(df), ...)
563569
cat("\n")
564-
cat("Use `as.data.frame()` to extract full results.\n")
565570

571+
if (has_tibble) {
572+
cat("Use `as.data.frame()` or `as_tibble()` to extract full results.\n")
573+
} else {
574+
cat("Use `as.data.frame()` to extract full results.\n")
575+
}
576+
566577
invisible(x)
567578
}
568579

R/zzz.R

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
.onLoad <- function(libname, pkgname) {
77
op <- options()
88
op.boxr <- list(
9-
boxr.token = NULL,
10-
boxr_token_jwt = NULL,
11-
boxr.wd = list(id = 0, name = "All Files"),
12-
boxr.wd.path = "",
13-
boxr.verbose = TRUE,
14-
boxr.progress = TRUE,
15-
boxr.interactive = TRUE
9+
boxr.token = NULL,
10+
boxr_token_jwt = NULL,
11+
boxr.wd = list(id = 0, name = "All Files"),
12+
boxr.wd.path = "",
13+
boxr.verbose = TRUE,
14+
boxr.progress = TRUE,
15+
boxr.interactive = TRUE,
16+
boxr.print_tibble = FALSE
1617
)
1718
toset <- !(names(op.boxr) %in% names(op))
1819
if (any(toset)) options(op.boxr[toset])

man/boxr_options.Rd

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)