Tables in R Markdown

Discuss the jamovi platform, possible improvements, etc.
Whirly123
Posts: 31
Joined: Mon May 06, 2019 3:07 pm

Re: Tables in R Markdown

Post by Whirly123 »

No that's not it either but I do have a slightly strange "solution":

Code: Select all

a <- capture.output(TResults$desc)
#a <- gsub("-", "\u2500", a)
a <- gsub("-", "_", a)
a <- gsub(" ", "\U00A0", a)
a <- gsub(",", "\U2424", a)

cat('<p style="font-family: Lucida Console">')
cat (a, quote = FALSE)
cat("</p>")

It looks like this:

Annoyingly this does not round to the correct amount of decimal places.
Attachments
1.jpg
1.jpg (85.09 KiB) Viewed 5987 times
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Tables in R Markdown

Post by jonathon »

you control the decimal places with:

options(digits=...)

cheers
DeborahA
Posts: 22
Joined: Tue Apr 14, 2020 11:38 am

Re: Tables in R Markdown

Post by DeborahA »

Hi Jonathan,

I'm having a similar issue too, but not with the CSS format exactly - I'm trying to get the tables into an R Markdown document but just using kable, but I'm having a lot of trouble getting them to look any good. At first I was flummoxed by the active object binding, but now I've worked out I can do e.g.

Code: Select all

pupilResults <- jmv::anovaRM(
    data = PupilDilation,
    rm = list(
        list(
            label="Task",
            levels=c("WM", "ATT"))),
    rmCells = list(
        list(
            measure="wm_Allexp",
            cell="WM"),
        list(
            measure="att_allexp",
            cell="ATT")),
    bs = exp,
    rmTerms = ~ Task,
    bsTerms = ~ exp)
and then, e.g.,

Code: Select all

knitr::kable(pupilResults$rmTable$asDF)
But this looks, quite frankly, awful without a great degree of fiddling and renaming.

Is there a better way of doing this? I am hoping for a nice way to introduce my students to RMarkdown, but at the moment this isn't really cutting it.

Thanks!

Deborah.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Tables in R Markdown

Post by jonathon »

hi deborah,

something odd has changed in knitr recently, and we've been quite puzzled by it. it's been throwing errors when printing the jmv tables. we've added fixes to jmvcore, but haven't pushed it to CRAN yet. can you try:

remotes::install_github('jamovi/jmvcore')

then restart R, and that should solve the active binding issues.

jonathon
DeborahA
Posts: 22
Joined: Tue Apr 14, 2020 11:38 am

Re: Tables in R Markdown

Post by DeborahA »

Hi Jonathon,

Oh, that's great, I'll try that. I managed to solve most problems with the CSS code at the top of this thread, but some of the tables come out in odd formats (for instance, descriptives are all in one row of the df, which isn't super useful in a table).

I'm now struggling with a different problem - one of the papers I'm working on has some Bayesian analyses using jsq, but the jsq R package doesn't seem to exist yet. Do you have a GitHub version of that as well?

Thanks!

Deborah.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Tables in R Markdown

Post by jonathon »

yup,

remotes::install_github('jonathon-love/jsq')

jonathon
DeborahA
Posts: 22
Joined: Tue Apr 14, 2020 11:38 am

Re: Tables in R Markdown

Post by DeborahA »

Hi Jonathan,

Ah, great, thanks, I did that, but it's producing an empty object, I think?

Code: Select all

jsq::bcorrMatrix(
    data = mainData,
    vars = vars(unmasked_N2pc_E, Umasked_D_prime),
    plotDens = TRUE,
    plotPost = TRUE)
It runs, but nothing appears in the console. Any clues?

Thanks!

Deborah.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Tables in R Markdown

Post by jonathon »

hey, thanks for reporting, update your jmvcore again, restart R, and you should be in business:

remotes::install_github('jamovi/jmvcore')

jonathon
DeborahA
Posts: 22
Joined: Tue Apr 14, 2020 11:38 am

Re: Tables in R Markdown

Post by DeborahA »

Awesome, that worked a treat! Thanks!

Cheers

Deborah.
Post Reply