Check all is ready for R4PHD course

Check at alting er klar til R4PHD kurset
Author

Søren O’Neill & Steen Harsted

Published

February 8, 2023


Assuming you now have a working installation of R and RStudio, do the following:

  1. First unfold the call-out box below (‘Installation checker’)

  2. Next copy the code presented in the code listing by clicking the clip-board icon in the right hand corner of the code listing filed, which appears on mouse-over

  3. Close the call-out box again

# This script is intented to test whether the basic
# requirements for an R-installation is met, prior
# to taking part in the R4PHD courses.

### Operating system

sys_name <- Sys.info()[['sysname']]
sys_version <- Sys.info()[['release']]
sys_machine <- Sys.info()[['machine']]

if (sys_name %in% c("Linux", "MacOS", "Windows")) {
  print(paste0("[OK] Your operating system is ", sys_name, " (version ", sys_version,")"))
} else {
  print(paste0("[WARNING] Your operating system is reported as '", sys_name, "'. 'Linux', MacOS' or 'Windows' was expected."))
}

### CPU architecture

if (sys_machine %in% c("x86_64", "amd64", "arm64", "x86-64")) {
  print("[OK] You computer has a 64 bit CPU")
} else if (sys_machine %in% c("i386", "i586", "i686")) {
  print("[WARNING] You computer has an older 32 bit CPU")
} else {
  print(paste0("[WARNING] You computer is reported as ",sys_machine," ... not what was expected."))
}

### R version

r_version_major <- R.Version()[['major']]
r_version_string <- R.Version()[['version.string']]

if (r_version_major >= "4") {
  print(paste0("[OK] R installation is: ", r_version_string))
} else {
  print(paste0("[WARNING] An R version 4.x.x is recommended. You installation is ", r_version_string))
}

### RStudio version

rstudio_type <- rstudioapi::versionInfo()$mode
rstudio_version <- rstudioapi::versionInfo()$version

if (rstudio_type == "desktop") {
  print("[OK] The RStudio installation is 'desktop'")
} else {
  print(paste0("[WARNING] The RStudio installation is '", rstudio_type,"'. Version 'desktop' is recommended!"))
}

if (rstudio_version > "2023") {
  print(paste0("[OK] The RStudio version is ",rstudio_version))
} else {
  print(paste0("[WARNING] The RStudio version is ",rstudio_version, ". Version 2023+ was expected."))
}

all_installed_packages <- .packages(all.available = TRUE)
recommended_packages <- c("tidyverse", "here", "patchwork", "gt", "gtsummary", "ggstatsplot",  "easystats", "rstatix", "naniar", "readr", "readxl", "vroom", "colourpicker", "colorspace")

for (p in recommended_packages) {
  if (p %in% all_installed_packages) {
    print(paste0("[OK] '", p, "' (package) is installed."))
  } else {
    print(paste0("[WARNING] '", p, "' (package) is NOT installed."))
  }
}

print("The following packages are consider 'extra' - don't fret if they're not installed yet")

extra_packages <- c("ggthemes", "gganimate", "ggiraph", "kableExtra", "gtExtras", "glue", "gapminder", "ggside")

for (p in extra_packages) {
  if (p %in% all_installed_packages) {
    print(paste0("[OK] '", p, "' (package) is installed."))
  } else {
    print(paste0("[NOTE] '", p, "' (package) is not installed."))
  }
}
  1. Open RStudio

  2. Create a new, empty R Script by keyboard: CTRL-SHIFT-n or menu: File / New File / R Script

  3. Paste the code into the empty document

  4. Execute all the code by keyboard: CTRL-SHIFT-s, or menu: Code / Source or mouse: click ‘Source’ in the top-right hand corner of the text editor panel.

  5. Examine the output in the Console

1 Problems?

Look at the output of the R script: Any [WARNING] messages?

If any of the recommended packages are not installed, then go ahead and install them as described on the previous page ‘R package installation’.

Hvis du nu har en fungerende installation af R og RStudio, skal du gøre følgende:

  1. Udfold først callout boksen nedenfor (‘Installationskontrol’)

  2. Kopier derefter koden fra kodefeltet ved at klikke på udklipsholderikonet i højre hjørne af kodefeltet, som vises når musen er over feltet

  3. Luk callout boksen igen

# This script is intented to test whether the basic
# requirements for an R-installation is met, prior
# to taking part in the R4PHD courses.

### Operating system

sys_name <- Sys.info()[['sysname']]
sys_version <- Sys.info()[['release']]
sys_machine <- Sys.info()[['machine']]

if (sys_name %in% c("Linux", "MacOS", "Windows")) {
  print(paste0("[OK] Your operating system is ", sys_name, " (version ", sys_version,")"))
} else {
  print(paste0("[WARNING] Your operating system is reported as '", sys_name, "'. 'Linux', MacOS' or 'Windows' was expected."))
}

### CPU architecture

if (sys_machine %in% c("x86_64", "amd64", "arm64", "x86-64")) {
  print("[OK] You computer has a 64 bit CPU")
} else if (sys_machine %in% c("i386", "i586", "i686")) {
  print("[WARNING] You computer has an older 32 bit CPU")
} else {
  print(paste0("[WARNING] You computer is reported as ",sys_machine," ... not what was expected."))
}

### R version

r_version_major <- R.Version()[['major']]
r_version_string <- R.Version()[['version.string']]

if (r_version_major >= "4") {
  print(paste0("[OK] R installation is: ", r_version_string))
} else {
  print(paste0("[WARNING] An R version 4.x.x is recommended. You installation is ", r_version_string))
}

### RStudio version

rstudio_type <- rstudioapi::versionInfo()$mode
rstudio_version <- rstudioapi::versionInfo()$version

if (rstudio_type == "desktop") {
  print("[OK] The RStudio installation is 'desktop'")
} else {
  print(paste0("[WARNING] The RStudio installation is '", rstudio_type,"'. Version 'desktop' is recommended!"))
}

if (rstudio_version > "2023") {
  print(paste0("[OK] The RStudio version is ",rstudio_version))
} else {
  print(paste0("[WARNING] The RStudio version is ",rstudio_version, ". Version 2023+ was expected."))
}

all_installed_packages <- .packages(all.available = TRUE)
recommended_packages <- c("tidyverse", "here", "patchwork", "gt", "gtsummary", "ggstatsplot",  "easystats", "rstatix", "naniar", "readr", "readxl", "vroom", "colourpicker", "colorspace")

for (p in recommended_packages) {
  if (p %in% all_installed_packages) {
    print(paste0("[OK] '", p, "' (package) is installed."))
  } else {
    print(paste0("[WARNING] '", p, "' (package) is NOT installed."))
  }
}

print("The following packages are consider 'extra' - don't fret if they're not installed yet")

extra_packages <- c("ggthemes", "gganimate", "ggiraph", "kableExtra", "gtExtras", "glue", "gapminder", "ggside")

for (p in extra_packages) {
  if (p %in% all_installed_packages) {
    print(paste0("[OK] '", p, "' (package) is installed."))
  } else {
    print(paste0("[NOTE] '", p, "' (package) is not installed."))
  }
}
  1. Åbn RStudio

  2. Opret et nyt, tomt R-script med: CTRL-SHIFT-n eller menu: Files / New fil / R-script

  3. Indsæt koden i det tomme dokument

  4. Eksekvér al koden med: CTRL-SHIFT-s, eller menu: Code / Source eller mus: klik på ‘Source’ i øverste højre hjørne af tekstredigeringspanelet.

  5. Inspicér output i konsollen

2 Problemer?

Se på outputtet af R-scriptet: Er der nogen [WARNING]-meddelelser?

Hvis nogen af de anbefalede pakker ikke er installeret, så fortsæt og installer dem som beskrevet på den forrige side ‘R-pakkeinstallation’.