Search code examples
rr-markdownmarkdownquarto

Line break for content of code chunk in quarto document


Is there a way to insert a line break inside a code chunk in quarto?

While rendering with xelatex the content sometimes just gets over the line and is hidden.

Code chunk:

{r, result, results='asis'}
#create dataframe with results
result <- data.frame(Model=c("Logistic Reg.: Unscaled features",
                             "Logistic Reg.: Unscaled features",
                             "Logistic Reg.: Scaled features",
                             "Logistic Reg.: Scaled features",
                             "ANN",
                             "ANN",
                             "ANN & adjusted hyperparameters",
                             "ANN & adjusted hyperparameters"),
                      Data=c("in sample","out of sample","in sample","out of                                  sample","in sample","out of sample","in sample","out                              of sample"),
                     Accuracy= c(accuracy_log_train_unscaled,accuracy_log_test_unscaled,accuracy_log_train,accuracy_log_test,accuracy_ann_in,accuracy_ann_out,accuracy_ann_in_adj, accuracy_ann_out_adj)
                     )
            
newdata <- result[order(-result$Accuracy),]
setDT(newdata)

The line Accuracy just ignores the side margin.

Output: enter image description here


Solution

  • Try chunk option:tidy: styler, e.g. or this:

    ---
    title: "Untitled"
    format: pdf
    ---
    
    
    ```{r}
    result <- data.frame(Model=c("Logistic Reg.: Unscaled featuressssssssssssssssssssssssssssssssssssssss",
                                 "Logistic Reg.: Unscaled features",
                                 "Logistic Reg.: Scaled features",
                                 "Logistic Reg.: Scaled features",
                                 "ANN",
                                 "ANN",
                                 "ANN & adjusted hyperparameters",
                                 "ANN & adjusted hyperparameters"),
                          Data=c("in sample","out of sample","in sample","out of                                  sample","in sample","out of sample","in sample","out                              of sample"))
    
    ```
    
    ```{r, tidy='styler'}
    result <- data.frame(Model=c("Logistic Reg.: Unscaled featuressssssssssssssssssssssssssssssssssssssss",
                                 "Logistic Reg.: Unscaled features",
                                 "Logistic Reg.: Scaled features",
                                 "Logistic Reg.: Scaled features",
                                 "ANN",
                                 "ANN",
                                 "ANN & adjusted hyperparameters",
                                 "ANN & adjusted hyperparameters"),
                          Data=c("in sample","out of sample","in sample","out of                                  sample","in sample","out of sample","in sample","out                              of sample"))
    
    ```
    

    Result:

    enter image description here