fread showProgress as message - r

I am using fread to read in data as part of a .Rnw file I am working on. The file is big, 6 million rows, and I like the showProgress option. However, when I knit, the output appears in the final pdf. Elsewhere in the file, I print progress using message(), which I suppress in opts_chunk. Is there any way to print the progress as a message or in some other way that it doesn't appear in my final output?

You could set options(datatable.showProgress = FALSE) in your first code chunk. This will disable data table progress bar printing (by default) for the rest of the document.

Related

Use texreg::wordreg within whole markdown knitted Word document

I want to use texreg::wordreg within a Markdown file with several other calculations that I want to finally knit to an MS Word file. However, the function demands that I enter a file name and hence export each table separately. Is there a workaround that I could use so I don't need extra files for each table? I already tried "file = NULL" but it doesn't work (Error: "'file' must be a valid file path.")
That's the expected behaviour of wordreg.
Try
texreg::knitreg(your_list_of_models, center = FALSE)
It should automatically adapt your texreg table based on the type of document that you are knitting.

Can I check for duplicate labels before knitting the whole document using knitr?

I have a report made of several Rmd files (several layers of child documents).
I always end up doing a copy paste and forget to change the chunk names, it's annoying because the report takes minutes to knit before the error pops up.
I use the chunk names to debug, and in the end they're often the ones that make my code crash, there has to be a better way.
How can I check programmatically that everything's clear before attempting to knit ?
Apparently there exists this option that allows you to keep duplicate chunk labels and still knit:
options(knitr.duplicate.label = 'allow')

Redirect Output to Message r

Is it possible to capture output that is printed by a function and instead output it via message? I am running a report using knitr that deals with very large tables (millions of rows) and I have message statements in the code so I can have an idea of where I am. This works fine as I simply set the global chunk option to message = F and I can see the message in the console and it does not show up in the final pdf. However, I use fread to read the data from a file, and the showProgress option does not print a message! Setting the chunk option to results='hide' prevents the progress from being printed to the final document, but it also prevents me from seeing it at all, so that is unhelpful. Any help would be appreciated, thanks!

How to debug a Rsweave

I have an rsweave file that I run almost twice a week. Last time I used it a change a couple of things and when I run it to compile to pdf I got the following errors:
The pdf compiles complitly, and the only thing I notice that the error did is that the the pdf output has a extra page (the first one) all blank. I don't know how to make a reproducible example of the errors because I don't know whats the cause of it. But any way I just want to know generally how to debug a rsweave file when getting latex error like the ones in the picture
You don't say how you are running Sweave, but that looks like RStudio. To debug something like this, just run Sweave explicitly in the R console, e.g. if your input file is source.Rnw, run
Sweave('source.Rnw')
This will produce source.tex. Open that file in a text editor and look at the start of it. You will see that \Schunk is used on line 27, but \begin{document} doesn't occur until sometime later.
My guess is that you added some text or a code chunk to the header. All text belongs after \begin{document}.
Edited to add: It turns out from the comments below that you were using print(...) in a code chunk before \begin{document}. In Sweave, print output goes into the document. If you want a message to show up in the console log but not the document, use message("some text"). You'll also need to suppress the echoing of the command if you want to do this in the document header. For example,
<<echo=FALSE,results=hide>>=
message("Started at ", Sys.time())
#
will result in something like this in your console log:
1 : keep.source term hide (Untitled.Rnw:6)
Started at 2017-09-27 08:28:33
and nothing in the document.

Print message into R markdown console while knitting

I'm wondering if there is a way to print a message containing one of the variables into Rmarkdown console at the end of knitting?
I'm currently preparing an R Markdown template for others to use. I would like to inform the users about the readability index of the document once it finishes compiling. I have already found a way to calculate it in one of the chunks. Now I would like to automatically print it to the person who compiles it in a way that it is not shown in the final document. Any ideas?
Ben Bolkers comment is the perfect answer. I ended up putting:
{r cache = FALSE, echo = F, warning = F, message = F}
message(rdblty)
at the very bottom of the markdown file. rdblty is the variable calculated before that I wanted to print out.
How about ?
cat(file="readability.txt")

Resources