-1

Model Analysis Template (tidymodels) . I made a few minor edits to get this template started. Compiles great as HTML. Does not compile as PDF. downloaded tinytex and tried again. still does not compile. This was just a template that I wanted to start to use. Error Screenshot from RStudio attached.

enter image description here

Created a New R Markdown in Rstudio.

  1. Loaded Template: Model Analysis {tidymodels}
  2. Made some minor edits to headings and text. Not to the code it comes with.
  3. Compiles just fine (multiple times) as HTML. Compiles well as a WORD document as well. Problem is only in compiling as PDF.
  4. Changed Output Options to PDF.

Hangs up for quite a while and then gives an error message

> output file: 2023-rcDEA-RMDTEST.knit.md

LaTeX Error: Unicode character ^^[ (U+001B)
not set up for use with LaTeX.

Error: LaTeX failed to compile 2023-rcDEA-RMDTEST.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 2023-rcDEA-RMDTEST.log for more info.
Execution halted

Now I installed tinytext and retried. Again I get an error:

> set.seed(234)
> penguin_folds <- vfold_cv(penguin_train, strata = sex)
> penguin_folds
#  10-fold cross-validation using stratification 
> install.packages("tinytex")
Installing package into ‘C:/Users/sbalakrishnan/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/tinytex_0.45.zip'
Content type 'application/zip' length 136103 bytes (132 KB)
downloaded 132 KB

package ‘tinytex’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\sbalakrishnan\AppData\Local\Temp\Rtmp29YPNr\downloaded_packages
> 
  1. Not sure if I should give up on this Template?
  2. Compiles well as a WORD document as well. Problem is only in compiling as PDF.
Phil
  • 7,287
  • 3
  • 36
  • 66
Sundar
  • 1
  • 3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 30 '23 at 09:21

2 Answers2

0

For the Unicode error, read this.

In short:

  1. isolate the problem --- create some very simple .rmd documents and add parts to them until they break;

  2. turn off warning when knitting in .pdf (especially in tidyverse), for example:

```{r, warning = F}
# Your code with warning
```                                                                                      .
  1. (optional) use other latex engine, for example --- replace pdf_output: default to pdf_output: pdf_engine: xelatex

And I agree with the opinion above --- please clarify the question.

roma
  • 25
  • 8
0

OKAY CREW, I PUT A LOT OF EFFORT IN AND HAVE ISOLATED THE CHUNK IN THE Template: Model Analysis {tidymodels}. CHUNK ISOLATED:

bind_rows(
  collect_predictions(glm_rs) %>%
    mutate(mod = "glm"),
  collect_predictions(ranger_rs) %>%
    mutate(mod = "ranger")
) %>%
  group_by(mod) %>%
  roc_curve(sex, .pred_female) %>%
  autoplot()

output file: PDF-STACKOVERFLOW-EXmiddle-PROBLEM-CHUNK.knit.md

! Text line contains an invalid character. l.161 ## Please report the issue at <^^[ ]8;;https://github.com/tidymodels/...

Error: LaTeX failed to compile PDF-STACKOVERFLOW-EXmiddle-PROBLEM-CHUNK.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See PDF-STACKOVERFLOW-EXmiddle-PROBLEM-CHUNK.log for more info. Execution halted

NOTE: THERE IS NO LINE 161 IN THE CODE. WHEN YOU ADD THIS BACK IN PDF STOPS RENDERING.

THE moment I remove this chunk the PDF is generated. The problem is not in the YAML but in the above code chunk. Just for the record, here is the YAML and the first part of the code that works: [except, I now had to manually delete the URLs from the actual code as I am not yet allowed to post them!

title: "Evaluate DEA with tidymodels" date: "r Sys.Date()" output: pdf_document: toc: yes toc_depth: 1 fig_width: 7 fig_height: 5 fig_caption: yes number_sections: yes latex_engine: xelatex word_document: toc: yes toc_depth: 1 fig_caption: yes html_document: toc_depth: 1 fig_caption: yes number_sections: yes toc: yes df_print: kable

knitr::opts_chunk$set(echo = FALSE, fig.width = 6.5, fig.height = 5)

from species and measurement information.

library(tidymodels)

data(penguins)
glimpse(penguins)

penguins <- na.omit(penguins)

Explore data

Exploratory data analysis (EDA) is an [important part of the modeling process].

penguins %>%
  ggplot(aes(bill_depth_mm, bill_length_mm, color = sex, size = body_mass_g)) +
  geom_point(alpha = 0.5) +
  facet_wrap(~species) +
  theme_bw()
  • training and testing sets
  • create resampling folds from the training set
set.seed(123)
penguin_split <- initial_split(penguins, strata = sex)
penguin_train <- training(penguin_split)
penguin_test <- testing(penguin_split)

set.seed(234)
penguin_folds <- vfold_cv(penguin_train, strata = sex)
penguin_folds

model specification

for each model we want to try:

glm_spec <-
  logistic_reg() %>%
  set_engine("glm")

ranger_spec <-
  rand_forest(trees = 1e3) %>%
  set_engine("ranger") %>%
  set_mode("classification")

To set up your modeling code, consider using the [parsnip addin].

Now let's build a [model workflow] combining each model specification with a data preprocessor:

penguin_formula <- sex ~ .

glm_wf    <- workflow(penguin_formula, glm_spec)
ranger_wf <- workflow(penguin_formula, ranger_spec)

If your feature engineering needs are more complex than provided by a formula like sex ~ ., use a [recipe]

Evaluate models

These models have no tuning parameters so we can evaluate them as they are.

contrl_preds <- control_resamples(save_pred = TRUE)

glm_rs <- fit_resamples(
  glm_wf,
  resamples = penguin_folds,
  control = contrl_preds
)

ranger_rs <- fit_resamples(
  ranger_wf,
  resamples = penguin_folds,
  control = contrl_preds
)

How did these two models compare?

collect_metrics(glm_rs)
collect_metrics(ranger_rs)

We can visualize these results using an

ROC curve

(or a confusion matrix via conf_mat()):


so maybe helpful to others to understand why this chunk does not render. Also, i dont know how to report the issue as suggested in the output: "Please report the issue at <^^[ ]8;;https://github.com/tidymodels/... "

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '23 at 19:13