Hmisc::html output in RMarkdown not displaying certain text correctly.

Hello, I'm trying to use the Hmisc package but I'm keep getting strange text defects in Hmisc:html outputs. Here is my code.

## Hmisc package --------------
library(tidyverse)
library(Hmisc)
library(ucidata)

# Load wine data
data(wine)

# Re-code outcome
mydata <- wine %>%
  dplyr::mutate(red_wine = ifelse(color == "Red", 1, 0)) %>%
  dplyr::select(-color)

s <- Hmisc::summaryM(
  fixed_acidity + volatile_acidity + citric_acid + residual_sugar + chlorides + free_sulfur_dioxide +
    total_sulfur_dioxide + density + pH + sulphates + alcohol + quality ~ red_wine,
  data = mydata,
  overall = TRUE,
  test = TRUE,
  continuous = 5
)

html(s, caption='Predictors according to wine type',
     exclude1 = TRUE, npct = 'both', digits = 2,
     prmsd = TRUE, brmsd = TRUE, msdsize = mu$smaller2)

Both in RStudio notebook and preview (nb.html file), it shows this.

However, Knit can produce html file without this error. But I would like to see my work in RStudio while working.

Thank you!

Reproducibility fails here.

This data is from one of the package. What is not mention is that ucidata package is from Github not CRAN.

I don't really know what happens here, but this is due to this special ± character.

Here is a minimal reprex

---
output:
 html_document:
   df_print: paged
editor_options:
 chunk_output_type: inline
---

```{r}
htmltools::HTML(Hmisc::markupSpecs$html$plminus)
```

The markup character print well when knitting the document but does not show correctly on the RStudio IDE as inline output.

I would advice to maybe open an issue in Hmisc repo to get help to investigate

Thank you for your help. Interestingly, reprex does render correctly. Below is my reprex.

## Hmisc package --------------
library(tidyverse)
library(Hmisc)
#> Loading required package: lattice
#> Loading required package: survival
#> Loading required package: Formula
#> 
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:dplyr':
#> 
#>     src, summarize
#> The following objects are masked from 'package:base':
#> 
#>     format.pval, units
library(ucidata)

# Load wine data
data(wine)

# Re-code outcome
mydata <- wine %>%
  dplyr::mutate(red_wine = ifelse(color == "Red", 1, 0)) %>%
  dplyr::select(-color)

s <- Hmisc::summaryM(
  fixed_acidity + volatile_acidity + citric_acid + residual_sugar + chlorides + free_sulfur_dioxide +
    total_sulfur_dioxide + density + pH + sulphates + alcohol + quality ~ red_wine,
  data = mydata,
  overall = TRUE,
  test = TRUE,
  continuous = 5
)

html(s, caption='Predictors according to wine type',
     exclude1 = TRUE, npct = 'both', digits = 2,
     prmsd = TRUE, brmsd = TRUE, msdsize = mu$smaller2)

Predictors according to wine type.

0
N=4898

1
N=1599

Combined
N=6497

Test Statistic

fixed_acidity

6.30 6.80 7.30
6.85 ± 0.84

7.10 7.90 9.20
8.32 ± 1.74

6.40 7.00 7.70
7.22 ± 1.30

F1<U+2009>6495=1421, P<0.001

volatile_acidity

0.21 0.26 0.32
0.28 ± 0.10

0.39 0.52 0.64
0.53 ± 0.18

0.23 0.29 0.40
0.34 ± 0.16

F1<U+2009>6495=3637, P<0.001

citric_acid

0.27 0.32 0.39
0.33 ± 0.12

0.09 0.26 0.42
0.27 ± 0.19

0.25 0.31 0.39
0.32 ± 0.15

F1<U+2009>6495=173, P<0.001

residual_sugar

1.7 5.2 9.9
6.4 ± 5.1

1.9 2.2 2.6
2.5 ± 1.4

1.8 3.0 8.1
5.4 ± 4.8

F1<U+2009>6495=458, P<0.001

chlorides

0.036 0.043 0.050
0.046 ± 0.022

0.070 0.079 0.090
0.087 ± 0.047

0.038 0.047 0.065
0.056 ± 0.035

F1<U+2009>6495=5156, P<0.001

free_sulfur_dioxide

23 34 46
35 ± 17

7 14 21
16 ± 10

17 29 41
31 ± 18

F1<U+2009>6495=2409, P<0.001

total_sulfur_dioxide

108 134 167
138 ± 42

22 38 62
46 ± 33

77 118 156
116 ± 57

F1<U+2009>6495=5473, P<0.001

density

0.9917 0.9937 0.9961
0.9940 ± 0.0030

0.9956 0.9968 0.9978
0.9967 ± 0.0019

0.9923 0.9949 0.9970
0.9947 ± 0.0030

F1<U+2009>6495=1300, P<0.001

pH

3.09 3.18 3.28
3.19 ± 0.15

3.21 3.31 3.40
3.31 ± 0.15

3.11 3.21 3.32
3.22 ± 0.16

F1<U+2009>6495=829, P<0.001

sulphates

0.41 0.47 0.55
0.49 ± 0.11

0.55 0.62 0.73
0.66 ± 0.17

0.43 0.51 0.60
0.53 ± 0.15

F1<U+2009>6495=2101, P<0.001

alcohol

9.5 10.4 11.4
10.5 ± 1.2

9.5 10.2 11.1
10.4 ± 1.1

9.5 10.3 11.3
10.5 ± 1.2

F1<U+2009>6495=1.8, P=0.18

quality

5.00 6.00 6.00
5.88 ± 0.89

5.00 6.00 6.00
5.64 ± 0.81

5.00 6.00 6.00
5.82 ± 0.87

F1<U+2009>6495=100, P<0.001

a b c represent the lower quartile a, the median b, and the upper quartile c for continuous variables. x ± s represents X ± 1 SD.
Test used: Wilcoxon test .

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

I just reinstalled RStudio and it's still the same...

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.