5

I am using summary() to generate simple summaries of date variables in a knitr document and want to have the results nicely formatted.

summary(some_date)

produces the results I want (the values are displayed as dates) but it is not nicely formatted. So, I tried:

pander::pander(summary(some_date))

This produces nicely formatted results, but the values are displayed as integers instead of dates. (This is true for Date, POSIXct, and POSIXlt dates).

Is there some way to nicely format the results of a summary() of dates in a knitr document? Maybe there is some package other than pander which is better for this task.

Examples below:

summary(some_date)
##         Min.      1st Qu.       Median         Mean      3rd Qu. 
## "2014-05-01" "2015-02-15" "2015-06-17" "2015-05-05" "2015-09-08" 
##         Max. 
## "2015-11-21"

pander::pander(summary(some_date))
Min.    1st Qu. Median  Mean    3rd Qu. Max.
16191   16481   16603   16560   16686   16760

sessionInfo()
## R version 3.2.3 (2015-12-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 14.04.3 LTS
## 
## locale:
##  [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
##  [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
##  [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] pander_0.6.0  ggplot2_2.0.0 daff_0.1.4    magrittr_1.5  dplyr_0.4.3  
## [6] readr_0.2.2  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.2      knitr_1.11       munsell_0.4.2    lattice_0.20-33 
##  [5] colorspace_1.2-6 R6_2.1.1         plyr_1.8.3       stringr_1.0.0   
##  [9] tools_3.2.3      parallel_3.2.3   grid_3.2.3       packrat_0.4.6-4 
## [13] nlme_3.1-122     gtable_0.1.2     mgcv_1.8-7       DBI_0.3.1       
## [17] htmltools_0.2.6  lazyeval_0.1.10  yaml_2.1.13      assertthat_0.1  
## [21] digest_0.6.8     Matrix_1.2-3     formatR_1.2.1    curl_0.9.4      
## [25] evaluate_0.8     rmarkdown_0.9    labeling_0.3     V8_0.9          
## [29] stringi_1.0-1    scales_0.3.0     jsonlite_0.9.19
Ross Gayler
  • 653
  • 1
  • 8
  • 14
  • `pander::pander(summary(Sys.Date() + sample(-50:50, 100, TRUE)))` gives me nicely formatted dates, not integers.... Can you provide an example that reproduces your problem, or maybe include some output that shows what you're getting from "pander"? – A5C1D2H2I1M1N2O1R2T1 Dec 28 '15 at 11:55
  • Please update your question with the relevant session information or details about which versions of the relevant packages you're using. – A5C1D2H2I1M1N2O1R2T1 Dec 28 '15 at 12:22
  • Anando, I just tried your code snippet and got integers rather than dates. I am using pander 0.6.0, knitr 1.11, rmarkdown 0.9, and R 3.2.3. This is the first time I have used pander, so it's quite possible there is some global option I have not set properly. – Ross Gayler Dec 28 '15 at 12:27
  • 1
    This seems to be something recently introduced then. The version of "pander" my other system when I posted the first comment is slightly out of date. Temporary solution: Use `as.character`: `pander(as.character(summary(Sys.Date() + sample(-50:50, 100, TRUE))))`.... – A5C1D2H2I1M1N2O1R2T1 Dec 28 '15 at 12:34
  • Yay! That works for me: `pander(as.character(summary(Sys.Date() + sample(-50:50, 100, TRUE))))` - is this something that needs to be notified to the `pander` maintainers? – Ross Gayler Dec 28 '15 at 12:42
  • I've [added an issue](https://github.com/Rapporter/pander/issues/237). Feel free to comment in with further details that you think might be useful for them. – A5C1D2H2I1M1N2O1R2T1 Dec 28 '15 at 12:43
  • Thanks. You should probably mention that the behaviour differs from the earlier pander version. – Ross Gayler Dec 28 '15 at 13:00

1 Answers1

5

Thanks for the bug report, with the development version of pander it should now render correctly:

> pander::pander(summary(as.Date('2015-01-01') + 1:100))

-----------------------------------------------------------------
   Min.     1st Qu.     Median      Mean     3rd Qu.      Max.   
---------- ---------- ---------- ---------- ---------- ----------
2015-01-02 2015-01-26 2015-02-20 2015-02-20 2015-03-17 2015-04-11
-----------------------------------------------------------------
daroczig
  • 28,004
  • 7
  • 90
  • 124