Need to have the source created with Rmarkdown otherwise error message - r

Hello StackOverflow community,
I have been trying over the last few weeks using R Markdown to Knit HTML file.
While it use to run smoothly the previous time, over the last week I keep on getting the following error
Quitting from lines 43-92 (Vizualisation.Rmd)
Error in eval(lhs, parent, parent) :
object 'processed.feedback' not found
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> %>% -> eval -> eval
Execution halted
The thing is that my source 'processed.feedback' is loaded within my Global environment. But is not created with the .rmd but before in a script file.
If I do the wrangling as well in the same Rmarkdown the it works fine (no error). But I would love to keep the wrangling part in a separate file.
Any suggestion.
Thanks in advance for your feedback and help!
If you are at the Rstudio conference - enjoy!

The usual model is that R Markdown files do not see objects that are in your workspace: they start with a blank workspace, so that anyone can reproduce the computation. (There are ways to work in an existing workspace, but you shouldn't use them.)
If it takes too long to create an object in the Rmd code, then there are at least two options: turn on caching (so it only happens when necessary), or save the object in a separate file using save() and load it in your document using load(). Remember to distribute the save file along with the .Rmd file if you want to give this document to someone else.

Related

How to resolve Error in resolver stop on character in R

I have no sample data so pardon me. However, I am just looking for some basic information on this error. This only started occurring when I installed R 4.2.1. The full error is below. The data frame that the item is drawing from shows data when I go to the environment. Also, it occurs when I knit the document but not when I run the individual code chunk. The code chunk where this error occurs runs fine when I click the green triangle to the right.
Has anyone ever encountered this error? If so, what did you do to resolve it?
Quitting from lines 2863-2864 (Document-July-2022.Rmd)
Error in readLines(con, warn = FALSE) : cannot open the connection
Calls: <Anonymous> ... <Anonymous> -> enumerate_output_formats ->
read_utf8 -> readLines
In addition: There were 27 warnings (use warnings() to see them)
Update
I am able to temporarily resolve this issue by using setwd(S://and so on) in each of the code chunks that only lists the table or chart. Seems strange that I can resolve this by doing the setwd command in excess of 30 times in one markdown file.

My code will run as a chunk but gives me an error when I try to knit

Hi I'm new to R and I'm using RStudio Cloud for a university stats course.
The code I'm having trouble with will run as a chunk but when I try to knit the project it comes up with an error saying that the object 'filename' not found.
The 'filename' is listed in the global environment but it is a tbl_df, which I'm thinking is not the right kind of object for knitting.
It is difficult to answer without having all the code. And code is almost always better than a screenshot.
My guess is that you loaded the dataset X2019THBrier manually in RStudio. Thus you can access it in chunks, in the current R session, but not in the knitted R session.
You need to write commands to load the data. As you are loading an XLSX file, you might want to install the openxlsx package, and use the openxlsx::read.xlsx() command.

Error message while trying to create PDF in R Markdown

I'm trying to create a PDF in R Markdown and I keep getting this error message every time I try to click "Knit to PDF":
output file: test_4_for_r.knit.md
Output created: test_4_for_r.pdf
Error in tools::file_path_as_absolute(output_file) :
file 'test_4_for_r.pdf' does not exist
Calls: <Anonymous> -> <Anonymous>
In addition: Warning message:
In readLines(logfile) : incomplete final line found on 'test_4_for_r.log'
Execution halted
I do not have a lot of familiarity with RStudio, so I have no idea why I'm getting this message. I've read several things online saying creating PDFs in R Markdown requires several packages, but so far I've only found the name of knitr. That is the only one I have currently installed. I'm not sure if that is the issue or not.
Can someone please point me in the right direction on how to remedy this? Any help would be GREATLY appreciated.
In R-Studio Tools > Global Options, under the Sweave tab, try changing "Weave Rnw using:" from sweave to knitr. Also try
install.packages('tinytex')
tinytex::install_tinytex()
and then try to knit your PDF.
If those don't work, please paste the markdown code giving you trouble. Could you knit the example markdown file, found when you File > New File > R Markdown?

basename error in bookdown updates

I am working on packing my course notes together using bookdown. When I try to view my chapter updates using bookdown:::serve_book() or simply knitting the document (supposedly a shortcut to preview_chapter) I get the error message below. And only after updating.
Error in basename(with_ext(nms, ".html")) : path too long
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> split_chapters -> basename
Please delete MATH456_notes.md after you finish debugging the error.
Execution halted
If I remove the mentioned .md file, AND clean the whole project using rmarkdown::clean_site(), it will compile just fine. But if I make changes, and try to view the update I get the following message.
Any ideas what is going on? I really don't want to rebuild the entire book every time I want to preview the current chapter.
If i'm previewing the book, and make any small change, the auto-update/live preview also throws the same error.
I know this thread is old, but maybe my answer may help others in the future. :) So for all of you who still encounter this error:
For me, the problem can be fixed by checking all headings. Most likely you inserted a hashtag # in the wrong place (i.e. in the body text) without closing it, so Bookdown detects a new main chapter (i.e. level 1) that has an extremely long heading name.
I would recommend saving the index.rmd in a second backup file and then deleting each chapter individually, starting at the bottom. Once your book renders again with no problems, you will know which chapter is causing the problem. Watch out for problematic hashtags # and headings there.

Building R Packages and Class Definitions / class defs are not found

I am building an R package and have several files containing only class definitions (R6Classes, but I'm sure this applies to any kind). On building the package, I get an error due to some definitions not being found - e.g. the files are not loaded in the necessary order:
Error in R6Class("MyChildClass", inherit = DataSource,
public = list(initialize = function(...) {
(from MyChildClass.R#1) :
object 'DataSource' not found
Calls: <Anonymous> ... source_many -> source_one
-> eval -> eval -> R6Class
Execution halted
Exited with status 1.
I know about the Collate: field in DESCRIPTION, but there I have to write down every single .R file in the package. This is very cumbersome as the project grows in size...
Two other options occur to me:
Either put the starting-function in a file at the lexical end of the line (Z_Evaluate.R)
or wrap all class definition file (<FileName>) contents inside their own load function (LoadClassDefinitionsFrom<FileName>()) and call them at the beginning of the startup function in correct order.
Both don't really seem very convenient to me. If I'm not mistaken, the Latex compiler goes through the source twice in order to get everything right. That's probably not doable within R.
What's the best practise to deal with such a problem?

Resources