Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions spict/R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,30 @@ latex.figure <- function(figfile, reportfile, caption=''){
#' @return Nothing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns TRUE or invisible(NULL) depending on !keep.figurefiles, not nothing! But maybe it should return something like the pdf filename with full path, so one could open it using system(paste(getOption("pdfviewer"), outpdf), wait = FALSE). We can also have an argument to show the pdf file after creation.

#' @export
make.report <- function(rep, reporttitle='', reportfile='report.tex', summaryoutfile='summaryout.txt', keep.figurefiles=FALSE, keep.txtfiles=FALSE, keep.texfiles=FALSE){
if(basename(reportfile) == "") reportfile <- 'report.tex'
if(file.access(dirname(reportfile), mode=1) != 0) reportfile <- file.path(getwd(), reportfile)

# if file name specified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many comments and not all of them say what the code does. E.g. here the code checks if "tex" is between dots in the reportfile string, not if a file is specified. Small difference, but maybe crucial.

if("tex" %in% unlist(strsplit(basename(reportfile),"[.]"))){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test here could be: grepl(".+[.](tex)$", reportfile)

# use filename
FileName <- basename(reportfile)
# if no path specified
if(file.access(dirname(reportfile), mode = 1) != 0 | dirname(reportfile) == "."){
reportfile <- file.path(getwd(), FileName)
# if path exists
}else{
reportfile <- file.path(dirname(reportfile), FileName)
}
}else{
# if file name is empty - default file name
FileName <- "report.tex"
# if no path specified - getwd()
if(file.access(reportfile, mode = 1) != 0){
reportfile <- file.path(getwd(), FileName)
# if path exists
}else{
reportfile <- file.path(reportfile, FileName)
reportfile <- gsub(pattern = "//",replacement = "/",reportfile)
}
}

latexstart <- '\\documentclass[12pt]{article}\n\\usepackage{graphicx}\n\\usepackage{verbatim}\n\\begin{document}\n'
latexend <- '\\end{document}\n'
Expand Down Expand Up @@ -101,8 +123,12 @@ make.report <- function(rep, reporttitle='', reportfile='report.tex', summaryout

# -- Compile tex file -- #
#latexcompile <- system(paste('pdflatex -output-directory=../res/', reportfile), intern=TRUE)
latexcompile <- system(paste(paste0('pdflatex -output-directory=',file.path(dirname(reportfile))), file.path(reportfile)), intern=TRUE)
console_path1 <- gsub(x = file.path(dirname(reportfile)), pattern = " ", replacement = "\\\ ", fixed=TRUE)
console_path2 <- gsub(x = file.path(reportfile), pattern = " ", replacement = "\\\ ", fixed=TRUE)

latexcompile <- system(paste(paste0("pdflatex -output-directory=", console_path1),
console_path2), intern = TRUE)

# -- Remove temporary files -- #
#file.remove(paste0('../res/', substr(reportfile, 1, nchar(reportfile)-4), '.log'))
#file.remove(paste0('../res/', substr(reportfile, 1, nchar(reportfile)-4), '.aux'))
Expand Down