# Run this code to check your R installation
cat("R Version:", paste(R.version$major, R.version$minor, sep="."), "\n")
## R Version: 4.5.2
cat("Platform:", R.version$platform, "\n")
## Platform: x86_64-w64-mingw32
# This code checks and loads required packages
required_packages <- c(
"tidyverse", "rmarkdown", "knitr", "ggplot2", "dplyr",
"car", "lmtest", "sandwich", "stargazer", "broom"
)
cat("Loading required packages...\n\n")
## Loading required packages...
all_loaded <- TRUE
for (pkg in required_packages) {
tryCatch({
library(pkg, character.only = TRUE)
cat("✓", pkg, "loaded successfully\n")
}, error = function(e) {
cat("✗", pkg, "FAILED to load\n")
all_loaded <<- FALSE
})
}
## ✓ tidyverse loaded successfully
## ✓ rmarkdown loaded successfully
## ✓ knitr loaded successfully
## ✓ ggplot2 loaded successfully
## ✓ dplyr loaded successfully
## ✓ car loaded successfully
## ✓ lmtest loaded successfully
## ✓ sandwich loaded successfully
## ✓ stargazer loaded successfully
## ✓ broom loaded successfully
cat("\n")
if (all_loaded) {
cat("✓ All packages loaded successfully!\n")
} else {
cat("⚠ Some packages failed. Run the code in Appendix A to install them.\n")
}
## ✓ All packages loaded successfully!
# set working directory
setwd("C:/Users/God's Icon/Desktop/553-Statistical Inference/553 Lab Codes")
# Check current working directory
cat("C:/Users/God's Icon/Desktop/553-Statistical Inference/553 Lab Codes")
## C:/Users/God's Icon/Desktop/553-Statistical Inference/553 Lab Codes
cat(getwd(), "\n\n")
## C:/Users/God's Icon/Desktop/553-Statistical Inference/553 Lab Codes
list.files()
## [1] "~$3 Introductory Checklist.docx" "553 Introductory Checklist.docx"
## [3] "553 Lab Codes.Rproj" "data"
## [5] "EPI-553_Lab.html" "EPI 553_Lab.Rmd"
## [7] "figures" "Frimpong_Marina_Setup_Checklist.html"
## [9] "Frimpong_Marina_Setup_Checklist.Rmd" "outputs"
## [11] "rsconnect" "scripts"
rproj_files <- list.files(pattern = "\\.Rproj$", ignore.case = TRUE)
if (length(rproj_files) > 0) {
cat("✓ R Project file detected:", rproj_files[1], "\n")
} else {
cat("⚠ No R Project file found in this folder.\n")
cat("Create one in RStudio: File → New Project → Existing Directory → choose this folder\n")
}
## ✓ R Project file detected: 553 Lab Codes.Rproj
# Check for suggested folders
cat("\nFolder structure check:\n")
##
## Folder structure check:
folders <- c("data", "scripts", "outputs", "figures")
for (folder in folders) {
if (dir.exists(folder)) {
cat("✓", folder, "/ exists\n")
} else {
cat("○", folder, "/ (needs to be created)\n")
}
}
## ✓ data / exists
## ✓ scripts / exists
## ✓ outputs / exists
## ✓ figures / exists
dir.create("data")
dir.create("scripts")
dir.create("outputs")
dir.create("figures")
folders <- c("data", "scripts", "outputs", "figures")
for (folder in folders) {
if (dir.exists(folder)) {
cat("✓", folder, "/ exists\n")
} else {
cat("○", folder, "/ (needs to be created)\n")
}
}
## ✓ data / exists
## ✓ scripts / exists
## ✓ outputs / exists
## ✓ figures / exists
# Verify R Markdown package
if (require("rmarkdown", quietly = TRUE)) {
cat("✓ rmarkdown package is installed and loaded\n")
cat("✓ You can render to HTML, PDF, and Word formats\n\n")
cat("To render a document:\n")
cat("1. Click the 'Knit' button (top of editor) or press Ctrl+Shift+K\n")
cat("2. Select output format (HTML, PDF, Word)\n")
cat("3. View the rendered document in RStudio Viewer\n")
} else {
cat("✗ rmarkdown not found. Run: install.packages('rmarkdown')\n")
}
## ✓ rmarkdown package is installed and loaded
## ✓ You can render to HTML, PDF, and Word formats
##
## To render a document:
## 1. Click the 'Knit' button (top of editor) or press Ctrl+Shift+K
## 2. Select output format (HTML, PDF, Word)
## 3. View the rendered document in RStudio Viewer
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.