Tiki and PluginR

Tiki and PluginR

Re: a better R workflow on a webserver

posts: 37 France

I think I got some generic solution
Th R script is:

args < - commandArgs(trailingOnly = TRUE)
dir < - args[1]
input.path < - args[2]
output.path < - args[3]

s4r < - read.delim(file=input.path, header=TRUE, sep="|", skip="1", quote="")
save(s4r, file=output.path)

Then it is called by the shell script which crontab launches


STATS_FILE="stats_4_R.txt" # this is the csv which contains the data in STATS_FOLDER
RDA_FILE="stats_4_R.Rda" # This will be created in STATS_FOLDER
RDA_FILE_TMP="stats_4_R_tmp.Rda" # this is a temporary file to ensure RDA_FILE remains available during processing

/usr/bin/Rscript create_Rda.R "${STATS_FOLDER}" "${STATS_FILE}" "${RDA_FILE_TMP}"

echo -n "Rda file "
diff -q "${STATS_FOLDER}/${RDA_FILE_TMP}" "${STATS_FOLDER}/${RDA_FILE}" > /dev/null  && (echo "OK"; /bin/rm "${STATS_FOLDER}/${RDA_FILE_TMP}" ) || (echo "Replace"; /bin/mv "${STATS_FOLDER}/${RDA_FILE_TMP}" "${STATS_FOLDER}/${RDA_FILE}")