latex works for cph, generates .tex but does not work for anova tinytex or anova problem

i am following a simple example code follows

title: "ask_help.Rmd"
author: "testing"
date: "r Sys.time()"
pdf_document: default

word_document: default

css: style.css
toc: true
number_sections: true
code_folding: "hide"
fig_caption: true



levels(prostate$ekg)[levels(prostate$ekg) %in% c('old MI','recent MI')] <- 'MI'

#combine last 2 levels and use a new name

prostate$pf.coded <- as.integer(prostate$pf) 

levels(prostate$pf)<- c(levels(prostate$pf)[1:3],levels(prostate$pf[3]))

# combine last 2 levels

w <- transcan(~ sz + sg+ap+sbp + dbp + age+ wt + hg+ ekg + pf + bm + hx, imputed=TRUE, 
               data = prostate, pl=FALSE,pr=FALSE)
sz <- impute(w, sz, data=prostate)
sg <- impute(w, sg, data=prostate)
age <- impute(w, age, data=prostate)
wt <- impute(w, wt, data=prostate)
ekg <- impute(w, ekg, data=prostate)

dd <- datadist(prostate)

units(dtime) <- 'Month'
S <- Surv(dtime,status !='alive')

f <- cph(S~rx+rcs(age,4) + rcs(wt,4) + pf + hx +
           rcs(sbp,4) + rcs(dbp,4) + ekg + rcs(hg,4) + 
           rcs(sg,4)  + rcs(sz,4) + rcs(log(ap),4) + bm) #X matrix deemed to be singular; variable pf=confined to bed 

f <- cph(S~rx+rcs(age,4) + rcs(wt,4)  + hx +
           rcs(sbp,4) + rcs(dbp,4) + ekg + rcs(hg,4) + 
           rcs(sg,4)  + rcs(sz,4) + rcs(log(ap),4) + bm) #X matrix deemed to be singular; variable pf=confined to bed 

print(f,coefs = FALSE)


with the final anova statement I have a crash the message is
! Undefined control sequence.
l.251 paste0(``\textbackslash Needspace{2in}\n
'', caption), rowlabel = ````,

Error: LaTeX failed to compile ask_help.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See ask_help.log for more info.
Execution halted

Without the anova statement the .rmd works well and produces a simple pdf with a table down the bottom.

I have removed and reinstalled every application related to latex and are feeling a little stuck so any words of wisdom are well received.

It would seem that something is not defined - this would be one of the tinytex (environment) the anova code or perhaps my issue.


session info follows

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

[1] LC_COLLATE=English_New Zealand.utf8 LC_CTYPE=C LC_MONETARY=English_New Zealand.utf8
[4] LC_NUMERIC=C LC_TIME=English_New Zealand.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rms_6.3-0 SparseM_1.81 Hmisc_4.7-1 ggplot2_3.3.6 Formula_1.2-4 survival_3.4-0 lattice_0.20-45 tinytex_0.42

loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 mvtnorm_1.1-3 deldir_1.0-6 zoo_1.8-11 png_0.1-7 assertthat_0.2.1
[7] digest_0.6.30 utf8_1.2.2 R6_2.5.1 backports_1.4.1 MatrixModels_0.5-1 evaluate_0.17
[13] pillar_1.8.1 rlang_1.0.6 multcomp_1.4-20 rstudioapi_0.14 data.table_1.14.4 rpart_4.1.19
[19] Matrix_1.5-1 checkmate_2.1.0 rmarkdown_2.17 splines_4.2.1 stringr_1.4.1 foreign_0.8-83
[25] htmlwidgets_1.5.4 munsell_0.5.0 compiler_4.2.1 xfun_0.34 pkgconfig_2.0.3 base64enc_0.1-3
[31] htmltools_0.5.3 nnet_7.3-18 tidyselect_1.2.0 tibble_3.1.8 gridExtra_2.3 htmlTable_2.4.1
[37] codetools_0.2-18 fansi_1.0.3 dplyr_1.0.10 withr_2.5.0 MASS_7.3-58.1 grid_4.2.1
[43] nlme_3.1-160 polspline_1.1.20 gtable_0.3.1 lifecycle_1.0.3 DBI_1.1.3 magrittr_2.0.3
[49] scales_1.2.1 cli_3.4.1 stringi_1.7.8 latticeExtra_0.6-30 generics_0.1.3 vctrs_0.5.0
[55] sandwich_3.0-2 TH.data_1.1-1 RColorBrewer_1.1-3 tools_4.2.1 interp_1.1-3 glue_1.6.2
[61] jpeg_0.1-9 fastmap_1.1.0 yaml_2.3.6 colorspace_2.0-3 cluster_2.1.4 knitr_1.40
[67] quantreg_5.94

I looked at the code, but found no solution: the generated LaTeX code contains a macro with R code (??).
Maybe check the issues in and ask your question there (?)

Thanks for your trouble, I will try GitHub - harrelfe/rms: Regression Modeling Strategies

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.