I have tried all other solutions online, including those posted by the author of the knitr package. For some reason, every time I knit to pdf, it will not format the code correctly, and all the code falls off the page. I have been working on this for two weeks and have spent about 2-3 hours a day trying to solve it. Does anyone have an idea of why it isn't working?
I tried the styler package options, formatR options, etc. Below you can see the code using the solution for setting linewidth options in knitr, https://github.com/yihui/knitr-examples/blob/master/077-wrap-output.Rmd. I tried uploading the data file for anyone to reproduce the problem, but I can't upload an .rds file.
library(knitr)
hook_output = knit_hooks$get('output')
knit_hooks$set(output = function(x, options) {
# this hook is used only when the linewidth option is not NULL
if (!is.null(n <- options$linewidth)) {
x = xfun::split_lines(x)
# any lines wider than n should be wrapped
if (any(nchar(x) > n)) x = strwrap(x, width = n)
x = paste(x, collapse = '\n')
}
hook_output(x, options)
})
Study 1a
Data Prep
study1a <- read_rds("study1a.rds")
keys_list_study1a <- list(
infoavoid = c("Q103_4", "Q103_5", "-Q103_6", "Q103_7", "-Q103_8", "Q103_9", "-Q103_10", "-Q103_11"),
derog = c("-Q63_1", "Q63_5", "Q63_8", "Q63_9", "Q63_10"),
heartavoid = c("Q104_4", "Q104_5", "-Q104_6", "Q104_7", "-Q104_8", "Q104_9", "-Q104_10", "-Q104_11")
) #keys created identify items to be scored for each scale.
my_scales_study1a <- scoreItems(keys_list_study1a,
study1a,
totals = FALSE,
min = 1, max = 7, impute = "none") #Score items using keys list to create a new variable representing one score, the mean, for each scale for each person
#print(my_scales_study1a, short = TRUE)
study1a_scores <- my_scales_study1a$scores
study1a <- as_tibble(cbind.data.frame(study1a, study1a_scores))#add new variables to data set
study1a$derog[study1a$TestingDecision == 1] <- NA
x <- study1a %>% filter(TestingDecision == 0) # Data frame for correlations between predisposition to avoid and feedback derogation includes only those who received feedback (did not avoid)
I have tried all other solutions online, including those posted by the author of the knitr package. For some reason, every time I knit to pdf, it will not format the code correctly, and all the code falls off the page. I have been working on this for two weeks and have spent about 2-3 hours a day trying to solve it. Does anyone have an idea of why it isn't working?
I tried the styler package options, formatR options, etc. Below you can see the code using the solution for setting linewidth options in knitr, https://github.com/yihui/knitr-examples/blob/master/077-wrap-output.Rmd. I tried uploading the data file for anyone to reproduce the problem, but I can't upload an .rds file.
--- title: "Online Supplement" author: "Anonymous for Review" date: "
r Sys.Date()`" output: pdf_document: defaultStudy 1a
Data Prep
`