R Notebook preview

Hello,
I am trying to make a Codebook with R Notebook. I followed the instructions from You Tube Psych Prof channel (New Create Codebook Video - YouTube). Everything else works fine, but the preview notebook looks just like a basic R Markdown, no tabset, no darkly and so on. What could be the reason?

Example code:

title: "Test Notebook"
output:
html_notebook:
theme: darkly
toc: yes
toc_float: yes

Load Packages {. tabset}

Data Table

# Check if packages is already installed and install if not. Packages needed haven, summarytools, tidyverse, data table, rio and ggplot.
if  (!require (data.table)){
  install.packages("data.table", depandencies = TRUE)
  library (data.table)
}

haven

if  (!require (haven)){
  install.packages("haven", depandencies = TRUE)
  library (haven)
}

devtools

if  (!require (devtools)){
  install.packages("devtools", depandencies = TRUE)
  library (devtools)
}

if  (!require (remotes)){
  install.packages("remotes", depandencies = TRUE)
  library (remotes)
}
session_info()
```─ Session info ───────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.1.1 (2021-08-10)
 os       macOS Monterey 12.3
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Helsinki
 date     2022-10-11
 rstudio  1.4.1717 Juliet Rose (desktop)

Best Wishes, Anitra

Given that everything else worked fine, this is probably not the issue, but dependencies is misspelled.

You might also try updating RStudio. The latest version is 2022.07. The check for updates does not work with the change in their version numbering system. 1.4 is two or three versions back.

Thanks a lot. I will fix those.

Hello again. I corrected misspelling and updated R Studio and packages. Still the same. Previously I installed XQuartz for Mac and Homebrew. At some point, there was a warning about data.table and OpenMP issue on Mac.
It advised to be in contact with Apple Support, no help from there. Here is the code that I am trying to preview.

title: " MF Notebook"
output:
html_notebook:
theme: darkly
toc: yes
toc_float: yes

Load Packages {. tabset}

Data Table

if  (!require (data.table)){
  install.packages("data.table", dependencies = TRUE)
  library (data.table)
}

Haven

if  (!require (haven)){
  install.packages("haven", dependencies = TRUE)
  library (haven)
}

Devtools

if  (!require (devtools)){
  install.packages("devtools", dependencies = TRUE)
  library (devtools)
}

Remotes

if  (!require (remotes)){
  install.packages("remotes", dependencies = TRUE)
  library (remotes)
}

Summarytools

Requires XQuartz for Mac and Homebrew.
remotes::install_github("dcomtois/summarytools", force = TRUE)

library(summarytools)
colnames(mf2)

Select columns

MF <- mf2[, .(sp2, ika2, systbp2, lenght, weight, bmi)]

Rename multiple columns for old to new

setnames(MF, old = c('sp2','ika2','systbp2'), 
         new = c('gender','age','systbp'))

colnames(MF )
  1. REGEX ## Change improper quoting in colnames if needed.
colnames(MF) <- sub("\"", "", colnames(MF), fixed = TRUE) []
MF$gender <- sub("\"","", MF$gender)
MF$bmi <- sub("\"","", MF$bmi)

Data Frame Summary

dfSummary(MF)
  1. ROUNDING AND UNITS
MF [] <- MF[, bmi:=as.numeric(bmi)]
MF$bmi <- round(MF[, bmi], digits = 2)

I am trying to figure out, if there is a possible solution from these pages, if it has something to do with OpenMP, Mac and Data.table.

Best Regards, Anitra

My apologies, but I do not have XQuartz or Homebrew installed on any of my Mac computers, so I cannot be of much help with dfSummary. The OpenMP warning may just mean that it will not use multiple cores.

I assume your yaml code looks like this

---
title: " MF Notebook"
output:
  html_notebook:
    theme: darkly
    toc: yes
    toc_float: yes
---

You wrote that everything else works fine, but I am confused about one part of your code. That may be because I am more familiar with tidyverse functions rather than base R.

The period in mf2[, .(sp2, ika, systbp2, lenght, weight, bmi)] seems out of place. Also, length is misspelled.

Thank you again for pointing out the misspelling. The column name was misspelled in the original data. I just did not notice. MF < -mf2[, .(sp2, ika, systbp2, length, weight, bmi)] comes from data.table package and it selects columns from the original mf2 table.

Yes, that is my yaml code. I am running out of time, so decided to go with Ruben Arslan Codebook package and it works just fine. I will try to fix the Notebook issue later.

Best Regards, Anitra

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.