report/knitr/compileKnitR.R

#Taha Imzilen & Julien Barde - IRD - BlueBridge project http://www.bluebridge-vres.eu/ 

#R annotations to get OGC WPS metadata from 52North WPS Server Java API
# wps.des: id = compileKnitR, title = Generic R code to compile knitr documents, abstract =  This script is meant to enable the compilation of any knitr Code using open data and source code avilable through URLS or made available by complying with a template of sub-repositories coming along the knitr main code within a zip file;

# wps.in: id = repository, type = string, title = repository used to read report file, value = "/home/tomcat7/IRDTunaAtlas/";
# wps.in: id = file_prefix, type = string, title = Prefix of files to be used for compilation: name of ".Rnw" and ".R" .should be the same than the name of report file, value = "main_report";
# wps.in: id = upload_zip_knitr_report, type = string, title = Zip file containing all files required for knitR compilation, value = "";
# wps.in: id = URL, type = string, title = URL used to publish the pdf result , value = "http://mdst-macroes.ird.fr/tmp/reports/";

# wps.out: id = pdfresult, type = string, title = result pdf file path lis;
####################################################################################################
##############Tests on IRD server######################
#for local test (delete it before uploading in WPS)
# repository="/home/tomcat7/IRDTunaAtlas/"
# file_prefix="ICCAT_report"
# upload_zip_knitr_report="/tmp/ICCAT_report.zip"
# URL="http://mdst-macroes.ird.fr/tmp/"
##############Local Test on Julien PC######################
# repository="/home/julien/SVNs/GIT/IRDTunaAtlas/"
# file_prefix="test_julien_zip"
# upload_zip_knitr_report="/tmp/knitr_test_julien_wfs.zip"
# URL="http://mdst-macroes.ird.fr/tmp/"
#####################################################################################################

require(knitr)

#STEP 1 : Specify the working directory (path of the directory where the Github repository has been cloned) for the machine running the process
mywd <- repository

#STEP 2 : file.inout variable will store the prefix used for the names of the 2 default files expected to run the compilation:
#   * "name.Rnw" for the knitR code, 
#   * "name.R" to set up the R environment required to comple the knitR Code,
#   * "name.tex" will be generated by compiling "name.Rnw" with this file
file.inout <-file_prefix

#STEP 3 : The location (URL) of the zip file containing all the files needed to compile the document:
zip<-upload_zip_knitr_report

#STEP 4 : Execution of the function which compiles the knitR code
# Run_Report(path.inout = mywd,file.inout =file.inout,show.pdf=F)
Run_Report(path.inout = mywd,file.inout =file.inout, zip_file = zip, show.pdf=F)

#STEP 5 : returns the URL of the pdf result
pdfresult <- paste(URL,"/",file_prefix,".pdf",sep="")
juldebar/IRDTunaAtlas documentation built on March 9, 2024, 3:40 a.m.