Controlling display of significant digits in printing a tibble

I would like to be able to print a tibble without having underling of significant digits. Quite likely, there is an obvious way to do this and I am way off. So any advice is appreciated. (Note that the output shown in the reprex does not show the formatting. A snapshot with the underlining appears below.)

library(tidyverse)
library(pillar)
#> 
#> Attaching package: 'pillar'
#> The following object is masked from 'package:dplyr':
#> 
#>     dim_desc
foo <- tibble(aColumn =c(0.00001, -2))
print(foo)
#> # A tibble: 2 x 1
#>    aColumn
#>      <dbl>
#> 1  0.00001
#> 2 -2
options(pillar.subtle = FALSE)
print(foo)
#> # A tibble: 2 x 1
#>    aColumn
#>      <dbl>
#> 1  0.00001
#> 2 -2

Created on 2020-11-11 by the reprex package (v0.3.0)

image

As far as I know, there's no specific option in pillar that allows you to turn off underlining.

One alternative is to override the print.tbl_df() method and print tibbles as good old fashion data frames (see this post). But of course, you would lose ALL tibble-specific formatting which may not be desirable.

this is an option, ... but perhaps understanding your motivations/use case would help find a best solution.

library(tidyverse)

foo <- tibble(aColumn =c(0.00001, -2))

library(formattable)

(foo2 <- mutate(foo,
               bColumn=formattable(aColumn,formatter = function(x)
                                                        digits(x,5))
))
# A tibble: 2 x 2
   aColumn bColumn   
     <dbl> <formttbl>
1  0.00001  0.00001  
2 -2       -2.00000

image

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

First, thanks to both siddharthprabhu and nirgrahamunk for the very helpful advice. My real goal is to print out a table of some statistical results in a plain format. So I think you've each given me an avenue that should work. Also, this gives me a reason to learn about the formattable package, which I didn't know about.

The pillar package reads in part, "Set the pillar.subtle option to FALSE to turn off highlighting of significant digits." I read this as meaning I could use this to turn off underlining, but I guess I jumped to a conclusion.