Accidentally deleted .pdf knit in project files and now will not knit to .pdf

Hi folks. First post here and relatively new to RStudio.
I have a DAR report I'm trying to present in .pdf, but it kept crashing so I stupidly deleted the .pdf in the project files environment pane thinking it would regenerate on knit. It didn't.
How do I make it knit up to .pdf again?
Thanks!

There's too little information to tell. Can you try to answer the following questions?

  1. What OS are you using, which version of R and RStudio?
  2. Have you ever used knit in the time window between when you generated the PDF until you deleted it?
  3. Can you run through the sequence of chunks without crashing, starting with an empty global environment?
  4. What do you mean by 'crashing' (Error during knitting, no response, session termination)?

Assuming that your answer to 2. and 3. is 'no', you've likely added some changes that rely on some values being present in the global environment. You should look at the log to find out where the error occurs.

Assuming you answered yes to 3., and you are using Linux, perhaps there's a discrepancy between the library path used in the R Session and that used during knitting?

Assuming your answer to 4. is that the R Session is terminated and restarted, try to answer the following questions:

  1. Are you using Rcpp or Fortran code?
  2. Are you using parallel processing?
  3. Are you doing something that might consume too much system memory?

If you answered yes to 1., the crash might be related to memory management. For example, I once forgot to actually assign an address to a pointer in one of my Rcpp functions, resulting in the session being terminated upon calling it from within R.

Points 2. and 3. seem improbable to me, but it can't hurt to make sure.

Finally, if none of these questions helped to identify the issue, please attach some additional details about the packages you are using, and a rough description of what your code is supposed to be doing.

Edit: Also note that deleting the PDF wouldn't cause such a problem.

Hi thomascf.
Not sure how to answer a lot of this. It's RStudio Cloud on a laptop running MS Windows 11 Home edition. Knitting this rather chunk heavy document to pdf is definitely taxing the limited memory and seemed to "crash"...meaning not produce a pdf in a new window, about 50% of the time...maybe more. After it "crashed" three times in a row, I deleted the document from the project files pane thinking when I reknit it up, it would see there wasn't one and regenerate one. I've tried making a blank .pdf w the same name and importing it in, hoping that on knit, it would find it again, and regenerate the contents as originally done, but nope.

Hi BodhiSeeds

To me it sounds like an error occurs in one of the chunks, resulting in early termination of the knitting process. One think you could do to quickly evaluate whether this is what's happening is the following:

# Add this line to the setup chunk, typically the first chunk in your .Rmd file.
knitr::opts_chunk$set(error = TRUE)

By setting this value, the document will continue to be knit even after an error occurred, and the errors will then be displayed in the output document. You might also find some additional details in the log files.

Edit: If the document still does not knit correctly, there might be some issue with regards to your presentation. Perhaps a missing input file or so. Do you know whether you're using anything like a template for your presentation file? And are you per chance including mathematical formulae in some of your slides?

Hello again, thomascf!
So, I wound up just exporting all the files, and copying the entire Rmd doc into a new project. Knits fine again, now. I really appreciate the help. I was hoping to avoid that with an obvious fix that I just wasn't seeing, but it's all good now....on to trying to solve why my plots and graphics are all over the place on the pdf knit, and not where I coded them in...Aaaargh.

Hello BodhiSeeds

Glad to hear you managed to resolve your problem. Makes me wonder whether the issue was related to caching, but ultimately irrelevant if it works now.

With regard to your issue with figure placement, you may find the following resource helpful: 6.5 Control the placement of figures | R Markdown Cookbook (bookdown.org)

Hi thomascf.
So, I'd gone through the cookbook there, but may have missed this exact section. Either way, I tried all of this and it just kept giving me LaTex errors right at the end of the knit process.
Your link DID allow me to rephrase my search on google and it then came up with this link which I'd yet to find: How to make figures and text stay in the order you wrote them in R Markdown when convert to LaTeX! ยท GitHub

In it, the user "burchill" posted some great info and code that DID work exactly as advertised.
I just needed to pop this:
header-includes:
- \usepackage{placeins}
...into the YAML, just before the "output:" section.

And then this:
knitr::knit_hooks$set(plot = function (x, options) {
float_correct <- function(f, y, opts) {
if (is.null(opts$regfloat) || opts$regfloat==FALSE)
paste0(f(y, opts), "\n\n\FloatBarrier\n")
else
f(y, opts)
}
if (!is.null(options$out.width) || !is.null(options$out.height) ||
!is.null(options$out.extra) || options$fig.align != "default" ||
!is.null(options$fig.subcap)) {
if (is.null(options$fig.scap))
options$fig.scap = NA
return(float_correct(knitr:::hook_plot_tex, x, options))
}
return(float_correct(knitr:::hook_plot_md_base, x, options))
})

...went into the first chunk, just under the knitr::opts_chunk$set code on a new line.
DONE!
Lot's of white space around the figures, and some almost empty pages...I'll need to go chunk by chunk and change the fig sizes, but we are heading in the right direction. Thanks so much, again.
Have a great weekend man!

This topic was automatically closed 21 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.