metafor icon indicating copy to clipboard operation
metafor copied to clipboard

`escalc` class objects may have trouble printing with Rmarkdown/Quarto Documents

Open emstruong opened this issue 7 months ago • 2 comments

Hello,

When I have this R code in a chunk, it seems to have trouble printing

bcg <- metadat::dat.bcg
metafor::escalc(
  measure = "RR",
  ai = tpos, # Got tubercolis and in treatment
  bi = tneg, # Did not get tubercolis and in treatment
  ci = cpos, # Got tubercolis and in control
  di = cneg, # Did not get tubercolis and in control
  data = bcg,
  append = TRUE
) |> 
  dplyr::mutate(sei = sqrt(vi)) |> 
  head()

Image

However, when I remove the escalc class, by converting into a data.frame, then everything is fine.

bcg <- metadat::dat.bcg
metafor::escalc(
  measure = "RR",
  ai = tpos, # Got tubercolis and in treatment
  bi = tneg, # Did not get tubercolis and in treatment
  ci = cpos, # Got tubercolis and in control
  di = cneg, # Did not get tubercolis and in control
  data = bcg,
  append = TRUE
) |> 
  dplyr::mutate(sei = sqrt(vi)) |> 
  as.data.frame()

Image

emstruong avatar May 11 '25 00:05 emstruong

This works for me without any problems on the console or in an Rmarkdown document when rendering the document. This appears to be an issue with RStudio and their 'Chunk Output Inline' option. If you use 'Chunk Output in Console' it works just fine. I did some digging and I see where the issue is coming from. The development version circumvents the issue, so it should now print inline as well. However, note that you will get two inline outputs, the first arising from the extra space that is added before the data frame is printed. If this annoys you, you can use setmfopt(space=FALSE) to suppress that extra space.

wviechtb avatar May 18 '25 13:05 wviechtb

Thanks for the quick fix! @wviechtb I'll try to take a look at it when I get a chance

emstruong avatar May 18 '25 14:05 emstruong