Run .bat file using shell() in R - r

I'm using the console of PDFSam to split and merge some PDF files. I can do this semi-automatically using .bat files, but I would like to do the whole thing in R.
This code in my .bat file works:
C:
cd "/Program Files/pdfsam/bin/"
run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split
But this "equivalent" code in my R shell command returns no errors, but doesn't seem to work.
shell('C:
cd "/Program Files/pdfsam/bin/"
run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')
Is there an option I'm missing in my shell command? I've tried a few of the options listed in ?shell to no avail.
I'm using windows XP and
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)
Thanks,
Tom

You could pass multiple commands to shell by concatenating them by &, so below should work:
shell('C: & cd C:/Program Files/pdfsam/bin & run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')
But as a workaround you could temporary change R working directory:
current.wd <- getwd()
setwd("C:/Program Files/pdfsam/bin")
shell('run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')
setwd(current.wd)
If you do it frequent write a function:
shell.in.dir <- function(dir, ...) {
current.wd <- getwd()
on.exit(setwd(current.wd))
setwd(dir)
shell(...)
}
shell.in.dir("C:/Program Files/pdfsam/bin",
'run-console.bat -f "d:/delete/A_9.pdf" -o d:/delete -s BURST -overwrite split')

This isn't exactly an answer to your question, but you might try system("youBatFile.bat") as an alternative.

Related

Submitting R jobs via single ssh command using nohup bash -c

I used to work with an older university server where I could submit analysis jobs using commands like the following. The server was a bit dated and using C Shell.
ssh -t user#oldserver 'cd ~/hte_paper/Code; nohup tcsh -c "R CMD BATCH analysis-file1.r; R CMD BATCH analysis-file2.r" &'
With the Ubuntu 20.04 server images provided by the Uni I work at now, this doesn't work anymore. Neither of the following commands work, nor do any of the variations I've tried. What am I missing? I've been using these commands in Makefiles to automate some work and prefer that over using tmux.
ssh -t user#myserver 'cd ~/some/folder; nohup bash -c "R CMD BATCH analysis-file.r" &'
ssh -t user#myserver 'nohup bash -c "cd ~/some/folder; R CMD BATCH analysis-file.r" &'
A friend helped me figure it out. The following works.
ssh -t user#myserver "set -m; cd ~/some/folder; (R CMD BATCH analysis-file1.r; R CMD BATCH analysis-file2.r) &"

Debian Packaging Without Build Tool

I want to create a Debian package from a C program without the use of a build tool such as autotools or CMake. My debian/rules file:
#!/usr/bin/make -f
%:
dh $#
override_dh_auto_clean:
rm -f program
override_dh_auto_build:
gcc program.c -o program
override_dh_auto_install:
cp program /usr/local/bin
Upon running dpkg-buildpackage, I get:
dh: error: Unknown sequence application (choose from: binary binary-arch binary-indep build build-arch build-indep clean install install-arch install-indep)
It seems the issue was related to the fact that I was creating the file in a shell script heredoc that was expanding the $#, e.g.
cat <<EOF > debian/rules.temp
#!/usr/bin/make -f
%:
dh $#
EOF
Which should be:
all_symbol='$#'
cat <<EOF > debian/rules.temp
#!/usr/bin/make -f
%:
dh $all_symbol
EOF
An unrelated issue is to the location of the override_dh_auto_install To manually create Debian file hierarchy it should be:
override_dh_auto_install:
mkdir -p debian/PACKAGENAME/usr/bin
cp program debian/PACKAGENAME/usr/bin
Or, to have this done automatically:
cat <<EOF > debian/PACKAGENAME.install
program usr/bin
EOF

System command fails in R Studio but works in R from Terminal

I have a system command in R studio which fails whereas the same command works from R using Terminal in Mac. Could someone hint what is wrong here:
From RStudio:
> system('/bin/qt query -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmprObPeS/9c810678b567d9a52dec9a86/5.gz -v -d /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmprObPeS/94047c0ddd9fb36a892047be/0.phe.db -p "Phe=2" -g "count(UNKNOWN)<=0" -p "Phe=2" -g "HOM_ALT" > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmprObPeS/9c810678b567d9a52dec9a86/out.vcf')
gqt: SQL error 'no such table: ped' in query 'SELECT BCF_ID FROM ped WHERE Phe=2 ORDER BY BCF_ID;': No such file or directory
The error message appears to have something to do with the tool but it also shows No such file or directory error whereas the same command works from terminal as shown below.
From R Terminal:
> system('/bin/qt query -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmprObPeS/9c810678b567d9a52dec9a86/5.gz -v -d /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmprObPeS/94047c0ddd9fb36a892047be/0.phe.db -p "Phe=2" -g "count(UNKNOWN)<=0" -p "Phe=2" -g "HOM_ALT" > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmprObPeS/9c810678b567d9a52dec9a86/out.vcf')
The terminal command writes the output to the out.vcf file.

combining gunzip and tar commands in Solaris and AIX

I am running the below command to untar a file in Solaris and AIX:
# gunzip /opt/myfile.tar.gz | tar -xvf-
but I'm getting this error:
tar: Unexpected end-of-file while reading from the storage media.
What do I need to fix?
Why should this work? The default behaviour of gunzip unpacks the file in place, substitutes the packed file with the unpacked one and you didn't specified the nescessary command to put the uncompressed datastream to stdout. So the tar command doesn't receive anything through the pipe to process and so you get the errormessage you have seen.
This will work:
gunzip -c ../myfile.tar.gz | tar -xfv -
This command line was tested on a Solaris 11.3 ... older variants of Solaris may need a different sorting of the command line like
gunzip -c ../myfile.tar.gz | tar -xvf -
I think something like this should work but I I don't have a Solaris system to test it...
gzip -dc /opt/myfile.tar.gz | tar xvf -

How do I manually install meteor?

The automatic installer script from meteor meteor.sh stops due to internet connectivity. I looked into the installer script, commented out the lines that try to download the TARBALL. Here is what I did:
I copied the TARBALL_URL from the script:
https://meteorinstall-4168.kxcdn.com/packages-bootstrap/${RELEASE}/meteor-bootstrap-${PLATFORM}.tar.gz, replaced
${RELEASE} by 1.3.2.4,
${PLATFORM} by os.osx.x86_64,
pasted the link in my browser and downloaded a .tar.gz file.
After downloading the TARBALL, I commented out the following lines:
# rm -rf "$INSTALL_TMPDIR"
# mkdir "$INSTALL_TMPDIR"
# curl --progress-bar --fail "$TARBALL_URL" | tar -xzf - -C "$INSTALL_TMPDIR" -o
When I try to run the extracting command tar -xzf... it does nothing. Even when I try to extract using GUI, it gives nothing. It's not like the package is corrupted; there is no error message.
EDIT
commented out a few more lines:
# If you already have a tropohouse/warehouse, we do a clean install here:
# if [ -e "$HOME/.meteor" ]; then
# echo "Removing your existing Meteor installation."
# rm -rf "$HOME/.meteor"
# fi
TARBALL_URL="https://meteorinstall-4168.kxcdn.com/packages-bootstrap/${RELEASE}/meteor-bootstrap-${PLATFORM}.tar.gz"
# INSTALL_TMPDIR="$HOME/.meteor-install-tmp"
# rm -rf "$INSTALL_TMPDIR"
# mkdir "$INSTALL_TMPDIR"
# echo "Downloading Meteor distribution"
# curl --progress-bar --fail "$TARBALL_URL" | tar -xzf - -C "$INSTALL_TMPDIR" -o
# rm -rf "${INSTALL_TMPDIR}"
# just double-checking :)
# bomb out if it didn't work, eg no net
# test -x "${INSTALL_TMPDIR}/.meteor/meteor"
# mv "${INSTALL_TMPDIR}/.meteor" "$HOME"
I solved it. The extraction command actually extracts the folder to the $INSTALL_TMPDIR which is ~/.meteor-install-tmp but the files are hidden (dot preceded files such as .meteor/).
I commented out a few more lines and executed them manually.
Moved the .meteor folder to $HOME
Executed the script

Resources