if (exists("eval")) eval_code <- eval else eval_code <- FALSE
\pagebreak
cat("\n# R Packages", fill=TRUE) cat("To run the code you need to install following R packages: ", fill=TRUE) cat("\\newline ") cat("\\newline ") cat("R version:", paste0(R.Version()[c("major","minor")], collapse = "."), fill=TRUE) cat("\\newline ") cat("Package car, version:", paste0(packageVersion("car")), fill=TRUE) cat("\\newline ") cat("Package data.table, version:", paste0(packageVersion("data.table")), fill=TRUE) cat("\\newline ") cat("Package ggplot2, version:", paste0(packageVersion("ggplot2")), fill=TRUE) cat("\\newline ") cat("Package gridExtra, version:", paste0(packageVersion("gridExtra")), fill=TRUE) cat("\\newline ") cat("Package Hmisc, version:", paste0(packageVersion("Hmisc")), fill=TRUE) cat("\\newline ") cat("Package knitr, version:", paste0(packageVersion("knitr")), fill=TRUE) cat("\\newline ") cat("Package PerformanceAnalytics, version:", paste0(packageVersion("PerformanceAnalytics")), fill=TRUE) cat("\\newline ") cat("Package psych, version:", paste0(packageVersion("psych")), fill=TRUE) cat("\\newline ") cat("Package reshape2, version:", paste0(packageVersion("reshape2")), fill=TRUE) cat("\\pagebreak")
\pagestyle{empty}
cat("\n# R Code ", fill=TRUE)
cat("\\textcolor{blue}{Instructions ") cat("\\newline ") cat("If not already available, please install R, RStudio and the requiered packages listed on the previous page. Copy the code below, paste it carefully in a new R Script within RStudio. For a seamless copy \\& paste process, open the PDF report in a browser. Change the path to your data in the line} ") cat("`filepath <- ...` ") cat("\\textcolor{blue}{For Windows users, avoid using paths containing spaces. Run the code. Explore the results (numerical results in the Console, plots in the Plots tab). }")
```{whites, eval=FALSE, echo = eval_code}
suppressPackageStartupMessages(library(data.table)) suppressPackageStartupMessages(library(knitr)) suppressPackageStartupMessages(library(psych)) suppressPackageStartupMessages(library(Hmisc)) suppressPackageStartupMessages(library(reshape2)) suppressPackageStartupMessages(library(ggplot2)) suppressPackageStartupMessages(library(PerformanceAnalytics)) suppressPackageStartupMessages(library(gridExtra)) suppressPackageStartupMessages(library(car))
opar <- par(no.readonly = TRUE)
```r cat("\\# `Define the path to your data (please remark the forward slash)`") cat("\\newline ") cat("`filepath <-") cat(paste0("\"C:/",params$filename[1],"\"`"))
if (params$decimal == "auto"){ cat("\\# `Upload the data`") cat("\\newline ") datainput1 <- fread(params$filename$datapath, header = "auto", sep="auto", dec=".", encoding ="unknown", data.table = FALSE, na.strings = "") # Probably comma as decimal colnames <- sapply(datainput1, function(col) is.numeric(col) & Negate(is.integer)(col)) if (sum(colnames) == 0L){ cat(paste0("`df <- fread(filepath, header =\"auto\", sep =\"auto\", dec =\",\", encoding =\"unknown\", data.table = FALSE, na.strings = \"\")`")) } else { cat(paste0("`df <- fread(filepath, header =\"auto\", sep =\"auto\", dec =\".\", encoding =\"unknown\", data.table = FALSE, na.strings = \"\")`")) } } else { cat("\\# `Upload the data`") cat("\\newline ") cat(paste0("`df <- fread(filepath, header = \"auto\", sep =\"auto\", dec = \"", params$decimal,"\", encoding = \"unknown\", data.table = FALSE, na.strings = \"\")`")) }
cat("\\# `Convert characters to UTF-8 encoding`") cat("\\newline ") cat("\\## `Depending on your local R settings`") cat("\\newline ") cat("\\## `you could try to ignore and skip the next 4 lines`") cat("\\newline ") cat(paste0("`colnames(df) <- iconv(colnames(df),\"",params$enc_guessed,"\",\"UTF-8\")`")) cat("\\newline ") cat(paste0("`col_names <- sapply(df, is.character)`")) cat("\\newline ") cat(paste0("`df[ ,col_names] <- sapply(df[, col_names], function(col) iconv(col, \"",params$enc_guessed,"\", \"UTF-8\"))`"))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.