无法在RStudio服务器中为dplyr的tbl_df设置屏幕

问题描述:

我正在使用RStudio服务器(版本0.98.994)和dplyr(请参阅下面的会话信息)。但是打印tbl_df对象不适合屏幕。总有一些在每一行的末尾更多的字符(见在scroonshot红线)无法在RStudio服务器中为dplyr的tbl_df设置屏幕

enter image description here

我已经检查浏览器:打印tbl_df对象正在为Firefox,而不进行缩放,而不是Chrome和Internet Explorer 。浏览器历史记录在检查前是干净的。

感谢您的任何建议,以解决它。

> sessionInfo() 
R version 3.1.1 (2014-07-10) 
Platform: x86_64-unknown-linux-gnu (64-bit) 

locale: 
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C   LC_TIME=C   LC_COLLATE=C   LC_MONETARY=C  LC_MESSAGES=C  
[7] LC_PAPER=C   LC_NAME=C   LC_ADDRESS=C   LC_TELEPHONE=C  LC_MEASUREMENT=C  LC_IDENTIFICATION=C 

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] hflights_0.1  dplyr_0.4.1.9000 

loaded via a namespace (and not attached): 
[1] DBI_0.3.1  Rcpp_0.11.3 assertthat_0.1 magrittr_1.5 parallel_3.1.1 tools_3.1.1 
+0

这是RStudio一个已知的bug – hadley 2015-02-09 18:04:11

这看起来可能只是tbl_df打印方法,从而进一步截断第一栏时的空间非常紧张的结果。

下面是从dplyr:::trunc_mat代码段,用于在dplyr:::print.tbl_df

... 
rownames(df) <- NULL 
is_list <- vapply(df, is.list, logical(1)) 
df[is_list] <- lapply(df[is_list], function(x) vapply(x, 
    obj_type, character(1))) 
mat <- format(df, justify = "left") 
width <- width %||% getOption("dplyr.width", NULL) %||% getOption("width") 
values <- c(format(rownames(mat))[[1]], unlist(mat[1, ])) 
names <- c("", colnames(mat)) 
w <- pmax(nchar(values), nchar(names)) 
cumw <- cumsum(w + 1) 
too_wide <- cumw[-1] > width 
if (all(too_wide)) { 
    too_wide[1] <- FALSE 
    df[[1]] <- substr(df[[1]], 1, width) 
} 
... 

你也许可以调整的一个或多个参数来trunc_mat()print.tbl_df(),或者尝试打印使用不同的打印方法表。

您也可以尝试调整dplyr打印选项,这是像

> grep("dplyr", names(options()), value=TRUE) 
[1] "dplyr.print_max" "dplyr.print_min" "dplyr.strict_sql" 
+0

感谢您的建议。我尝试调整print.tbl_df中的宽度参数,但仍然遇到同样的问题。看来chrome和firefox会返回getOptions('width')的不同值,即firefox为193,chrome为221(均为全宽)。 – Bangyou 2015-02-09 01:51:42

+0

你可以尝试截断你的列名。 'dplyr'使用宽度选项,这取决于列宽 – 2015-02-09 02:01:11

+0

感谢您的建议。现在我知道如何通过调整print.tbl_df的参数来打印它。但是似乎RStudio Server中存在一个错误。我会向github报告,并在这里粘贴一个链接。 – Bangyou 2015-02-09 02:04:09