To knit an Rmd from the command line, you can do the following and it creates an HTML
Rscript -e "rmarkdown::knit('test.Rmd')"
I want to do this for many Rmds using GNU parallel, I've tried this and various versions of it where I move the quotes around
find -name "*.Rmd" | parallel Rscript -e "rmarkdown::render('{}')"
But I keep getting errors.
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `Rscript -e rmarkdown::render('./test.Rmd')'
I think this is something to do with where the quotation marks are because I get different errors depending on where I put them. What is the problem? Is it doing something funny like only trying to parallelize Rscript and not what comes after it?
From man parallel:
If you get errors like:
sh: -c: line 0: syntax error near unexpected token
sh: Syntax error: Unterminated quoted string
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
zsh:1: no matches found:
then you might try using -q.
So:
find -name "*.Rmd" | parallel -q Rscript -e "rmarkdown::render('{}')"
Related
When I run Rscript d:/s.R, it prompt:
invalid multibyte character in parser at line 1 Execution halted
the contens of s.R is:
paste("到达第","天",sep="")
and the encoding of s.R is UTF-8.
How to solve this issue?
Many thanks.
I am trying to invoke a function from command prompt, but I am not finding the correct way to invoke it.
This is my script:
echo "Hello World!"
test {
echo "Sample message"
}
I tried below ways:
sh-4.2$ main.sh test
Hello World!
./main.sh: line 5: usuage: command not found
A helpful message!
./main.sh: line 8: syntax error near unexpected token `}'
./main.sh: line 8: `}'
sh-4.2$ . main.sh test
Hello World!
sh: usuage: command not found
A helpful message!
sh: ./main.sh: line 8: syntax error near unexpected token `}'
sh: ./main.sh: line 8: `}'
sh-4.2$ . main.sh test()
sh: syntax error near unexpected token `('
Can you please help me in this.
Couple of issues here, the syntax for test function is wrong, you need have the parentheses around,
test() {
echo "Sample message"
}
export -f test
The export -f syntax allows you to export your functions to the shell; to run them from the command-line you need to source the script in the current shell as,
$ . ./main.sh
Hello World!
Now you can call the function test directly from the command line after having exported it from the script,
$ test
Sample message
Also a good practice to NOT have functions name test, because it is same name a shell built-in. Recommend using some custom names for that.
I have written a statement like typeset -l target_tbl. I am getting an error that typeset : not found.
I ran the same statement on prompt. It executed successfully. I am getting this error in script. Can anyone guide me?
Thanks!
Is there a way to write my R errors to a file? I run R on bash via:
R --vanilla < myprogram > myprogram.out &
When my program encounters an error (not a syntax error...like an illegal replacement or something) it stops but the error line isn't written to the output file and I don't know what the program was and a lot of the time I log out from the server while it runs.
Thanks,
Josh
Use the R CMD BATCH <infile> <outfile> syntax instead.
This command:
/usr/bin/mysqldump --add-drop-table -u myuser -pmypass mydb > "/home/myuser/dbBackups/"`date +%Y%m%d`".sql"
works fine from the command line but whenb cron runs it I get
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
The command is all on one line in the crontab as well so I'm confused by the line 0 and line 1 references...
Can anyone advise me as to what I am doing wrong there?
It's the obvious dumb question, but do you have the matching backquote in your crontab (crontab -l)?
The line one, line zero stuff isn't referring to the lines in the crontab, only to the 'lines' in the one-line script.
Updated:
Ah, I think I've got it. This is from crontab(5):
Percent-signs (%) in the command, unless escaped with backslash (\),
will be changed into newline characters, and all data after the
first % will be sent to the command as standard input.
So the percent characters in your date spec are being interpreted as newlines, which means the backquote isn't terminated before the newline, which would produce your error message.
So escape the percent characters. I'd forgotten that about crontab....
The easiest fix is probably to put the whole command in a shell script and just have that be run. So make a scriptName.sh file that contains the command you listed and have crontab call that script. That gets around all these odd problems.
Commands executed from cron do not have access to the environment variables from your login shell, including the path. So try the following (adding fully qualified path to date):
/usr/bin/mysqldump --add-drop-table -u myuser -pmypass mydb > "/home/myuser/dbBackups/"`/usr/bin/date +%Y%m%d`".sql"
Of course, verify if your date command is located elsewhere by running which date then adjust the path if necessary.