I'm trying to send a table to slack via slackr (slackr::slack_msg
), but using tibble::format.tbl_df
gives me a bunch of formatting guff that slack doesn't handle so elegantly:
[38;5;246m# A tibble: 6 x 11[39m
mpg cyl disp hp drat wt qsec vs am gear carb
[38;5;250m*[39m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m [3m[38;5;246m<dbl>[39m[23m
[38;5;250m1[39m 21.0 6. 160. 110. 3.90 2.62 16.5 0. 1. 4. 4.
[38;5;250m2[39m 21.0 6. 160. 110. 3.90 2.88 17.0 0. 1. 4. 4.
[38;5;250m3[39m 22.8 4. 108. 93. 3.85 2.32 18.6 1. 1. 4. 1.
[38;5;250m4[39m 21.4 6. 258. 110. 3.08 3.22 19.4 1. 0. 3. 1.
[38;5;250m5[39m 18.7 8. 360. 175. 3.15 3.44 17.0 0. 0. 3. 2.
[38;5;250m6[39m 18.1 6. 225. 105. 2.76 3.46 20.2 1. 0. 3. 1.
I thought an alternative solution would be to convert a dataframe into a string containing a formatted markdown table.
For instance:
df_to_markdown(head(mtcars))
#> | mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb |
#> |------|-----|------|-----|------|-------|-------|----|----|------|------|
#> | 21 | 6 | 160 | 110 | 3.9 | 2.62 | 16.46 | 0 | 1 | 4 | 4 |
#> | 21 | 6 | 160 | 110 | 3.9 | 2.875 | 17.02 | 0 | 1 | 4 | 4 |
#> | 22.8 | 4 | 108 | 93 | 3.85 | 2.32 | 18.61 | 1 | 1 | 4 | 1 |
#> | 21.4 | 6 | 258 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 | 1 |
#> | 18.7 | 8 | 360 | 175 | 3.15 | 3.44 | 17.02 | 0 | 0 | 3 | 2 |
#> | 18.1 | 6 | 225 | 105 | 2.76 | 3.46 | 20.22 | 1 | 0 | 3 | 1 |
Is there an existing, easy way to acheive this?
If there's a better solution to this problem, let me know.