13

I am working with data that has significant digits (i.e. digits after the "."). These digits appear when viewing my data both as a variable in base R, and also when the data is stored in a dataframe. However, they do not appear when I view the data in a tibble.

I need to view these significant digits for my work. Is there a way to make them appear when using tibbles?

Here is a reproducible example:

x has 5 significant digits, and 3 are displayed when using base R:

x = 1234.56789
x
[1] 1234.568

Within a data.frame, 3 significant digits are also displayed:

df = data.frame(x=x)
df
         x
1 1234.568

Within a tibble, though, 0 significant digits are displayed:

library(tibble)
df = tibble(x=x)
df
# A tibble: 1 x 1
      x
  <dbl>
1 1235.

Again, I am looking for a way to make more than 0 significant digits appear whening viewing my data in a tibble.

Here is the result of my sessionInfo():

R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] tibble_1.4.2      readr_1.1.1       choroplethr_3.6.2
[4] acs_2.1.3         XML_3.98-1.12     stringr_1.3.1    

loaded via a namespace (and not attached):
 [1] httr_1.3.1          maps_3.3.0          splines_3.5.1      
 [4] Formula_1.2-3       assertthat_0.2.0    sp_1.3-1           
 [7] latticeExtra_0.6-28 yaml_2.2.0          pillar_1.3.0       
[10] backports_1.1.2     lattice_0.20-35     glue_1.3.0         
[13] uuid_0.1-2          digest_0.6.15       RColorBrewer_1.1-2 
[16] checkmate_1.8.5     colorspace_1.3-2    htmltools_0.3.6    
[19] Matrix_1.2-14       plyr_1.8.4          pkgconfig_2.0.1    
[22] WDI_2.5             purrr_0.2.5         scales_0.5.0       
[25] jpeg_0.1-8          tigris_0.7          ggmap_2.6.1        
[28] htmlTable_1.12      ggplot2_3.0.0       nnet_7.3-12        
[31] lazyeval_0.2.1      cli_1.0.0           proto_1.0.0        
[34] survival_2.42-6     RJSONIO_1.3-0       magrittr_1.5       
[37] crayon_1.3.4        maptools_0.9-2      fansi_0.2.3        
[40] foreign_0.8-71      class_7.3-14        tools_3.5.1        
[43] data.table_1.11.4   hms_0.4.2           geosphere_1.5-7    
[46] RgoogleMaps_1.4.2   munsell_0.5.0       cluster_2.0.7-1    
[49] bindrcpp_0.2.2      compiler_3.5.1      e1071_1.7-0        
[52] rlang_0.2.1         classInt_0.2-3      units_0.6-0        
[55] grid_3.5.1          rstudioapi_0.7      rjson_0.2.20       
[58] rappdirs_0.3.1      htmlwidgets_1.2     base64enc_0.1-3    
[61] gtable_0.2.0        curl_3.2            DBI_1.0.0          
[64] reshape2_1.4.3      R6_2.2.2            gridExtra_2.3      
[67] knitr_1.20          dplyr_0.7.6         rgdal_1.3-3        
[70] utf8_1.1.4          bindr_0.1.1         Hmisc_4.1-1        
[73] stringi_1.2.4       Rcpp_0.12.18        mapproj_1.2.6      
[76] sf_0.6-3            rpart_4.1-13        acepack_1.4.1      
[79] png_0.1-7           spData_0.2.9.0      tidyselect_0.2.4   

1 Answer 1

16

you can set the option pillar.sigfig

options(pillar.sigfig = 1)
as_tibble(iris)
# # A tibble: 150 x 5
#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#           <dbl>       <dbl>        <dbl>       <dbl> <fct>  
#  1           5.          4.           1.         0.2 setosa 
#  2           5.          3            1.         0.2 setosa 
#  3           5.          3.           1.         0.2 setosa 
#  4           5.          3.           2.         0.2 setosa 
#  5           5           4.           1.         0.2 setosa 
#  6           5.          4.           2.         0.4 setosa 
#  7           5.          3.           1.         0.3 setosa 
#  8           5           3.           2.         0.2 setosa 
#  9           4.          3.           1.         0.2 setosa 
# 10           5.          3.           2.         0.1 setosa 


options(pillar.sigfig = 7)
tb = tibble(x=x)
tb
# # A tibble: 1 x 1
#            x
#        <dbl>
#   1 1234.568

See also:

?`tibble-options`

or online:

https://www.rdocumentation.org/packages/tibble/versions/1.4.2/topics/tibble-options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.