rmarkdown::render leads to error when output_file path is absolute - r

I have the R package, one of its function - produce report.
In the inst/markdown I have a template rep.rmd
In the package function ProduceReport() I have this code:
render.file <-"rep.Rmd"
render.file <- system.file(TEMPLATES.PATH, render.file, package=getPackageName())
render.dir <- dirname(render.file)
pdf.file <- "example.pdf"
rmarkdown::render(render.file , quiet = FALSE, output_format = "pdf_document",
output_file = pdf.file)
It works.
But If I change last line to:
rmarkdown::render(render.file , quiet = FALSE, output_format = "pdf_document",
output_file = "d:/help/me/please/example.pdf")
It does not work (all paths are exist). I have the error
"! Undefined control sequence. \grffile#filename ->d:\help
\me\please\example _files/figure-... l.148 ...example_files/figure-latex/unnamed-chunk-2-1}"
pandoc.exe: Error producing PDF Show Traceback Rerun with Debug
Error: pandoc document conversion failed with error 43 "
When I use this variant on linux server it also works
P.S.
I would like to emphasize, that the problem is probably not in the paths (I use standard procedure file.path() to avoid system problems, path in example only for demonstration).

Maybe it's not a very good workaround, but it works on WIN
lol <- rmarkdown::render(render.file , quiet = TRUE,
output_format = "pdf_document")
file.rename(lol, pdf.file)

You can try to use output_dir parameter of rmarkdown::render() function.

Related

Source multiple files in one folder in Rstudio

I have a folder with multiples R functions. I would like to source all these functions in R studio. I tried the following code, but it does not work. I found the following code here ()
sourceFolder <- function(folder, recursive = FALSE, ...)
{
files <- list.files(folder, pattern = "[.][rR]$",
full.names = TRUE, recursive = recursive)
if (!length(files))
stop(simpleError(sprintf('No R files in folder "%s"', folder)))
src <- invisible(lapply(files, source, ...))
message(sprintf('%s files sourced from folder "%s"', length(src), folder))
}
sourceFolder("C:/Users/Admin/Desktop/autots",recursive = TRUE))
However, I got this error:
> sourceFolder("C:/Users/Admin/Desktop/autots",recursive = TRUE)
Error in environment(lstar) : object 'lstar' not found
Called from: environment(lstar)
I do not know how to fix it. The package that I try to install it as a source can be found here http://stat.snu.ac.kr/heeseok/autots
Any help, please?

passing extra argumenets to devtools::build

Something seems to have changed in the devtoolspackage, so that the following commands, that used to run now give an error I can't decipher:
> Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.21/bin/gswin64c.exe")
> devtools::build(args = c('--resave-data','--compact-vignettes="gs+qpdf"'))
The filename, directory name, or volume label syntax is incorrect.
Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
System command error
I've tried other alternatives with other devtools commands, like just passing a single argument, but still get the same error
args = '--compact-vignettes="gs+qpdf"'
devtools::check_win_devel(args=args)
I'm using devtools 2.2.0, under R 3.5.2

R - capture output from system() to a txt file.

I want to capture all output from R console. I tried to use sink() function and txtStart() of library 'TeachingDemos'. However, none of them can capture the output from system() command.
For example
If I run the below codes:
zz <- file("log.txt")
sink(zz)
sink(zz, type = "message")
print('first layer message!!!!')
system("Rscript test1.R") #test1.R is a R script that print 'hello world'
sink(type = "message")
sink()
I can see the message 'hello world' in the R console. However, I cannot write it into log.txt. Is there any way to solve this?
Thanks
system("Rscript test1.R", intern = TRUE)

Running a .Rexec on a .Rmd from command prompt

So I've followed this blog to create an executable file called r2jekyll
Unfortunately, I'm on Windows so I've had to create the .Rexec called r2jekyll differently
the code for r2jekyll is here:
#!/usr/bin/env Rscript
library(knitr)
# Get the filename given as an argument in the shell.
args = commandArgs(TRUE)
filename = args[1]
# Check that it's a .Rmd file.
if(!grepl(".Rmd", filename)) {
stop("You must specify a .Rmd file.")
}
# Knit and place in _posts.
dir = paste0("../_posts/", Sys.Date(), "-")
output = paste0(dir, sub('.Rmd', '.md', filename))
knit(filename, output)
# Copy .png files to the images directory.
fromdir = "{{ site.url }}/images"
todir = "../images"
pics = list.files(fromdir, ".png")
pics = sapply(pics, function(x) paste(fromdir, x, sep="/"))
file.copy(pics, todir)
unlink("{{ site.url }}", recursive = TRUE)
That all works fine, I can run my r2jekyll rexec (thanks to this blog) it runs but nothing happens
I'm up to the last step to run the r2jekyll on a file i've called first_test.Rmd
I run the following code in command prompt
cd (go to directory where my r2jekyll and my first_test.Rmd are sitting)
then
r2jekyll.rexec first_test.Rmd (the blog author used this code, he is on a mac)
and I get the following error
Error: You must specify a .Rmd file.
Execution halted
So my question is: how do I get my r2jekyll.Rexec to do its thing to the first_test.Rmd

Not able to executing all text files from one folder by a Rscript

This is an R script for array quality metrics. The first step is going well but after the execution of the 2nd step an error occurs.
library(arrayQualityMetrics)
library(limma)
library(tcltk)
X <-tk_choose.files(caption = "Choose X")
maData<-read.maimages(X, source="agilent", other.columns = "g", green.only=TRUE)
eSet<-new("ExpressionSet", exprs = maData$other$g, annotation =maData$genes[,7])
arrayQualityMetrics(eSet, outdir="QC_C", force = TRUE, do.logtransform = TRUE)
The program is running now but it is showing this warning message:
The directory 'QC_C' has been created.
Warning messages:
1: In svgStyleAttributes(style) :
Removing non-SVG style attribute name(s): subscripts, group.number, group.value
2: In svgStyleAttributes(style) :
Removing non-SVG style attribute name(s): subscripts, group.number, group.value
Where am I getting wrong? Is this the errors in the file or the Rscript is wrong....
Give the full path of the folder under path as below:
scanFiles<-dir(path='/path/to/folder/',pattern = ".*.txt$")

Resources