I have an .Rmd file that previously had knitted without any problems. Now I am getting the following error when executing this instruction
confusionMatrix(prediction1, ssTesting$classe)
The error is
Error in get_engine(options$engine) : Unknown language engine 'test' (must be registered via knit_engines$set())
If I execute each chunk independently the error does not occur.
It only happens if I knit.
The error is independent of using version R-3.1.2 or R-3.2.1. I also set all the cache options to FALSE and made sure that all the libraries were correct but the error keeps appearing.
A simple typo in the beginning of the chunk ... ```{rtest.mod1} instead of ```{r test.mod1}
Hard to see but simple to fix.
Related
I am attempting to load an RDS file into an RMarkdown using the following code:
protests <- readRDS("protests.RDS")
and I get the error:
Error in gzfile(file, "rb") : cannot open the connection :
I had this file loaded before and it was working, but when I attempted to knit my RMarkdown I got the Error while opening file: no such file or directory notice
In attempting to fix that I typed the code to load the RDS file into the RMarkdown (it was previously in another document) and then it started giving me the above error. And then my code wouldn't work with that dataset.
I'e tried numerous ways to set the working directory and reload the file into R. Sometimes I can't get the file to load, sometimes it loads but gives me a vec_size error whenever I use the dataset, and sometimes the code works but my RMarkdown still won't know.
Currently I've got the dataset to load into the environment by typing the readRDS() into a different RMarkdown (but the readRDS() in my first RMarkdown still won't work despite being the exact same) and the code in the first RMarkdown in working, but it won't knit.
Does anybody have an idea what is going on?
After I deploy my R shiny App in web server, it produced such errors. Can anyone help me to solve it? Thanks.
This error is very weird. I can run it in Shiny web server (http://www.shinyapps.io/). But I can not run it on my own web server. I commented out the code which produce pdf. But the error is still existing.
su: ignore --preserve-environment, it's mutually exclusive to --login.
Listening on http://127.0.0.1:37436
Warning: Error in : cannot open file 'Rplots.pdf'
48:
Execution halted
The following code solves my problem:
chown -R shiny:shiny /srv/shiny-server
When generating plots on Shiny server, it automatically tries to create a PDF file.
You can remove this functionality by having the below in your code, before the plotting function.
pdf(file = NULL)
This is probably because your code has a function that generates a plot, and the server is, by default, trying to save it to a pdf file because it's a non-interactive session (that is, it does not display it on the screen).
The fix is to find that statement and remove it.
I'm trying to publish an RMarkdown document to my RPubs account, but I get the next error when clicking on "Publish":
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:/Users/.../File.Rmd': No such file or directory
It also pops up a window saying the next two warnings:
First pop up: "Could not Publish - Error ocurred while executing method"
Second pop up: "Could not Publish - (TypeError): null is not an object evaluating 'b.g.')
My R version is 3.4.2, RStudio version is 1.1.383, knitr version is 1.17.
I have also checked is the working directory contains the files I'm using at the script, and all seems properly set.
This error only happens when I click on Publish. If I try to knit to HTML or to PDF it works. I have tried to restart and reinstall also both R and RStudio but the error persists.
Has anyone had the same error and knows how to solve it?
Thank you very much!
Is the file saved? Are you in the correct directory?
Please check getwd().
I managed to solve it. The problem was that the path of the working directory contained an accent. I changed the path to another folder without accents and it worked.
I am trying for the first time to get knitr running on texmaker, I followed this documentation and I am on Windows 7. However, when I compile, I get the following error stack:
Process started
Error in readLines(if (is.character(input2)) { : cannot open the connection Calls: <Anonymous> -> knit -> readLines
In addition: Warning message: In readLines(if (is.character(input2)) { : cannot open file 'try_easy.Rnw': No such file or directory
Execution halted
Process exited with error(s)
I tried to google it, but only found references to linux/unix, which were not helpful for my case. Following is my short test document:
\documentclass[a4paper]{article}
\begin{document}
<<a>>=
x=rnorm(100)
<<b>>=
<<a>>
mean(x)
#
\end{document}
It's my first time on stackoverflow, so please tell me if you need more information or I did something wrong. Thank you very much.
Update
Hello everyone,
I managed to find out my mistake. For the sake of future google-searchers, I had saved the file as a .tex instead as .rnw. Saving as rnw solved it. Since I cannot answer my own questions, I edit it here.
This error happens when the file is saved as a .tex instead of a .Rnw, as the compiler does not know that he should "knitr-compile" files that have the .tex handle, unless you specifically set him up like that.
I've often been frustrated by R's cryptic error messages. I'm not talking about during an interactive session, I mean when you're running a script. Error messages don't print out line numbers, and it's often hard to trace the offending line, and the reason for the error (even if you can find the location).
Most recently my R script failed with the the incredibly insightful message: "Execution halted." The way I usually trace such errors is by putting a lot of print statements throughout the script -- but this is a pain. I sometimes have to go through the script line by line in an interactive session to find the error.
Does anyone have a better solution for how to make R error output more informative?
EDIT: Many R-debugging things work for interactive sessions. I'm looking for help on command-line scripts run through Rscript. I'm not in the middle of an R session when the error happens, I'm at the bash shell. I can't run "traceback()"
Try some of the suggestions in this post:
General suggestions for debugging in R
Specifically, findLineNum() and traceback()/setBreakpoint().
#Nathan Well add this line sink(stdout(), type="message") at the beginning of the script and you should get in console message both script content and output along with error message so you can see it as in interactive mode in the console. (you can then also redirect to a log file if you prefer keeping the console "clean")
Have a look at my package tryCatchLog (https://github.com/aryoda/tryCatchLog).
While it is impossible to improve the R error messages directly you can save a lot of time by identifying the exact code line of the error and have actual variables at the moment of the error stored in a dump for "post mortem" analysis!
The main advantages of the tryCatchLog function over tryCatch are
easy logging of errors, warnings and messages into a file or console
warnings do not stop the program execution (tryCatch stops the execution if you pass a warning handler function)
identifies the source of errors and warnings by logging a stack trace with a reference to the source file name and line number (since traceback does not contain the full stack trace)
allows post-mortem analysis after errors by creating a dump file with all variables of the global environment (workspace) and each function called (via dump.frames) - very helpful for batch jobs that you cannot debug on the server directly to reproduce the error!
This will show a more detailed traceback, but not the line number:
options(error = function() {traceback(2, max.lines=100); if(!interactive()) quit(save="no", status=1, runLast=T)})
One way inside a script to get more info on where the error occurred is to redirect R message to the same stream as errors :
sink(stdout(), type="message")
This way you get both messages and errors in the same output so you see which line raised the error...