I am running Symfony and Ghostscript and I cannot get shell_exec to execute the script.
Simple test to make sure shell_exec() works inside of Symfony: it works, I can see the directory structure
$output = shell_exec('ls') and output the results ...
From terminal: it works and it creates the PDF file
/usr/local/bin/gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=/file/path/file-c.pdf -dBATCH /file/path/file-a.pdf /file/path/file-b.pdf ...
From inside of Symfony: it does not work
$output = shell_exec('/usr/local/bin/gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=/file/path/file-c.pdf -dBATCH /file/path/file-a.pdf /file/path/file-b.pdf');
If I output the results print_r($output), I just get the following but file-c.pdf is not created...
GPL Ghostscript 9.23 (2018-03-21) Copyright (C) 2018 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details.
If I do a "which gs" I get the following:
/usr/local/bin/gs
What could I be doing wrong in this example?
Why would it work from the terminal but fail in the shell_exec()? I can run other commands from shell_exec() and they work fine.
I am trying to install TinyTeX via the convenient tinytex-package for R.
After having had a few issues with getting the installation to run smoothly on MacOS, the install_tinytex() function now executes properly and ends with the statement:
TinyTeX installed to /Users/X/Library/TinyTeX
However, when trying to execute pdflatex('test.tex') to test the installation, the console instead returns:
Error: Failed to compile test.tex
Apparently the installation did not execute properly. Am I missing something or isn't this supposed to work after a successful TinyTeX installation via tinytex?
The texput.log displays the following error message:
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.11.2) 2 NOV 2018 14:47
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**test.tex
! Emergency stop.
<*> test.tex
Here is how much of TeX's memory you used: 3 strings out of 494585
99 string characters out of 6174649 51539 words of memory out of
5000000 3743 multiletter control sequences out of 15000+600000 3640
words of font info for 14 fonts, out of 8000000 for 9000 14
hyphenation exceptions out of 8191 0i,0n,0p,1b,6s stack positions out
of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
The quoted error message indicates that there is no file test.tex in your current working directory. Either create a sample LaTeX file or use an existing file. If you do not have any LaTeX file available, you can try
pdflatex('sample2e.tex')
This will translate smaple2e.tex, which should be part of every LaTeX distribution.
I have a strange error. When I try to build the package in Rstudio in the Build window I get this Error. I mean this ��� symbols.
I tried to set Encoding: cp1251 and Encoding: UTF-8 in the
'DESCRIPTION' it did not help.
I tried to run Rstudio in compatibility mode with Windows 7 and run
as administrator it did not help.
I tried to set the Project Options -> Text encoding -> UTF-8 and
Global options -> Code -> save -> Default text encoding -> UTF-8 and
it didn't help.
P.S. My system is Windows 10 x64 English. And English and Russian Languages
I'm coding in R.
I thought I was making pretty good progress in R. I had created a script that read the command line arguments (there was 1 single argument, it was the name of a data file), read in data from a .csv, performed a regression and printed some data.
Somewhere along the way, I modified something and everything went out the window. Subsequently, I have torn down my entire script and I now have the most basic script and it is behaving strangely. Here is what I've got now:
#NOTE: To run the script use the following command in terminal R CMD
#BATCH scriptname arguments #store the current directory
initial.dir<-getwd()
#set the output
sink("PROGOUT.out")
#Get commandline arguments
args<-commandArgs(trailingOnly=TRUE)
print(args)
"HELLO WORLD"
I expected this program to create a file, PROGOUT.out, that contains the commandline arguments and the phrase HELLO WORLD.
At the command prompt I ran,
$ R CMD BATCH R_ScriptV3.R test1 test2 test3 test4
The program creates two files, 'test1' and 'PROGOUT.out'
This is the contents of PROGOUT.out:
character(0)
[1] "HELLO WORLD"
proc.time() user system elapsed 0.201 0.026 0.219
This is the contents of test1:
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin10.8.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] >
NOTE: To run the script use the following command in terminal
R CMD BATCH scriptname arguments > > #store the current directory
initial.dir<-getwd()
set the output
sink("PROGOUT.out")
Get commandline arguments
args<-commandArgs(trailingOnly=TRUE)
print(args)
"HELLO WORLD" >
So... 1) why did the program create the file 'test1'? This wasn't happening when I started scripting but it appears the first argument in the command prompt becomes a file with some header information and a copy of the program?, 2) PROGOUT.out does contain the 'HELLO WORLD' statement but it does NOT contain any other arguments .... why not and how do I read those arguments into my script.
I could have SWORN this was all working just fine before. Any ideas?
You're looking for Rscript:
Rscript R_ScriptV3.R test1 test2 test3 test4
The params of R CMD BATCH work differently:
R CMD BATCH '--args test1 test2 test3 test4' R_ScriptV3.R output.Rout
I would like to produce a log-file which keeps track of all commands (stdin), results (stdout) and errors/warnings/messages (stderr) in the R console.
I am aware that there are a lot of logging-packages and I tried several like TeachingDemos (seems to ignore stderr completely) or R2HTML (seems to ignore messages), however, none of them seems to include everything from stderr.
Only knitr and markdown seem to be able to include everything into a single file. But using this workaround, I have to write R-scripts and I cannot freely write commands in the console. Furthermore, I cannot include the knitr or markdown command in the same R-script (which is of course a minor problem).
Here is an example:
library(TeachingDemos)
library(R2HTML)
library(TraMineR)
logdir <- "mylog.dir"
txtStart(file=paste(logdir,"test.txt", sep=""), commands=TRUE,
results=TRUE, append=FALSE)
HTMLStart(outdir = logdir, file = "test", echo=TRUE, HTMLframe=FALSE)
## Messages, warnings and errors
message("Print this message.")
warning("Beware.")
"a" + 1
geterrmessage()
## Some example application with the TraMiner package
## which uses messages frequently
data(mvad)
mvad.seq <- seqdef(mvad[, 17:86])
mvad.ham <- seqdist(mvad.seq, method="HAM")
txtStop()
HTMLStop()
If you are running R from a Unix/Linux/Mac/etc. terminal, you can do:
R | tee mydir/mylog.txt
On windows, you can run the script in
R CMD BATCH yourscript.R
and your result will appear in the same folder as yourscript.out
On unices, I've often used the following code idiom with bash:
Some Command 2>&1 | tee NameOfOutputFile.txt
The "2>&1" says to take stderr and redirect it to stdout, which then gets piped to "tee". I will be experimenting with this and other ways of logging an R session.
Another unix trick is the "script" command, which starts a subshell whose I/O (basically everything you type and see in return) is logged to the specified file. And then exit the shell to end the script. Again, subject to experimentation. Since "sink" is native to R, I'll be trying that first.
By the way, I picked these tricks up using solaris, but they work the same running Cygwin, the unix emulator on Windows. Long time ago, I found that my Cygwin images were more up-to-date than the institutional installations of Solaris because the administrators had much more responsibility than just keeping the Solaris up-to-date. Mind you, the institutional machines were more powerful, so even though Cygwin was way more convenient, my personal machine simply didn't fill the need.
AFTERNOTE:
I took example code from page 99 of Shumway's Time Series Analysis and Its Applications With R examples. Here are the contents of a test file palette.R:
r
plot(gnp)
acf2(gnp, 50)
gnpgr = diff(log(gnp)) # growth rate
plot(gnpgr)
acf2(gnpgr, 24)
sarima(gnpgr, 1, 0, 0) # AR(1)
sarima(gnpgr, 0, 0, 2) # MA(2)
ARMAtoMA(ar=.35, ma=0, 10) # prints psi-weights
quit("no")
exit
I invoked it using:
script < palette.R
It captures the commands from palette.R and the corresponding output. So, seems usable for batch mode. For interactive mode, I'm going to go with my original plan and use sink.
I had a similar problem and in my case, I was unable to redirect truly all the output into my log file, as it was dependent on R running in interactive mode.
Specifically, in my log file, I wanted to be able to keep track of the progress bar generated by the rjags::update() function which, however, requires interactive mode:
The progress bar is suppressed if progress.bar is "none" or NULL, if
the update is less than 100 iterations, or if R is not running
interactively.
Therefore, I needed to trick R into thinking that it was running interactively, while it was in fact run from a bash script (interactive_R.sh, below) using here document:
interactive_R.sh
#!/bin/bash
R --interactive << EOT
# R code starts here
print(interactive())
quit("no")
# R code ends here
EOT
(Sidenote: Make sure to avoid the $ character in your R code, as this would not be processed correctly - for example, retrieve a column from a data.frame() by using df[["X1"]] instead of df$X1.)
Then you can simply run this script and send its contents into a log file using the bash command below:
$ ./interactive_R.sh > outputFile.log 2>&1
Your log file will then look as follows:
outputFile.log
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
> # R code starts here
> print(interactive())
[1] TRUE
> quit("no")