Commit d63104b1 authored by Gael  MILLOT's avatar Gael MILLOT
Browse files

fun_open() implemented for linux in parallel

parent 8247e5e1
......@@ -4,7 +4,7 @@
## ##
## Gael A. Millot ##
## ##
## Compatible with R v3.5.3 ##
## Compatible with R v3.6.1 ##
## ##
################################################################
 
......@@ -2722,14 +2722,25 @@ ini.par <- par(no.readonly = TRUE) # to recover the initial graphical parameters
invisible(dev.off()) # close the new window
}else if(Sys.info()["sysname"] == "Linux"){
if(pdf.disp == TRUE){
if(file.exists(paste0(path.fun, "/recover_ini_par.pdf"))){
tempo.cat <- paste0("\n\n================\n\nPROBLEM IN fun_open(): THIS FUNCTION CANNOT BE USED ON LINUX IF A recover_ini_par.pdf FILE ALREADY EXISTS HERE: ", paste(path.fun, collapse = " "), "\n\n================\n\n")
# code that protects set.seed() in the global environment
# see also Protocol 100-rev0 Parallelization in R.docx
if(exists(".Random.seed", envir = .GlobalEnv)){ # if .Random.seed does not exists, it means that no random operation has been performed yet in any R environment
tempo.random.seed <- .Random.seed
on.exit(assign(".Random.seed", tempo.random.seed, env = .GlobalEnv))
}else{
on.exit(set.seed(NULL)) # inactivate seeding -> return to complete randomness
}
# end code that protects set.seed() in the global environment
set.seed(NULL)
tempo.code <- sample.int(1e6, size = 1)
if(file.exists(paste0(path.fun, "/recover_ini_par", tempo.code, ".pdf"))){
tempo.cat <- paste0("\n\n================\n\nPROBLEM IN fun_open(): THIS FUNCTION CANNOT BE USED ON LINUX IF A recover_ini_par", tempo.code, ".pdf FILE ALREADY EXISTS HERE: ", paste(path.fun, collapse = " "), "\n\n================\n\n")
stop(tempo.cat)
}else{
pdf(width = width.fun, height = height.fun, file=paste0(path.fun, "/recover_ini_par.pdf"), paper = paper)
pdf(width = width.fun, height = height.fun, file=paste0(path.fun, "/recover_ini_par", tempo.code, ".pdf"), paper = paper)
ini.par <- par(no.readonly = TRUE) # to recover the initial graphical parameters if required (reset). BEWARE: this command alone opens a pdf of GUI window if no window already opened. But here, protected with the code because always a tempo window opened
invisible(dev.off()) # close the pdf windows
file.remove(paste0(path.fun, "/recover_ini_par.pdf")) # remove the pdf file
file.remove(paste0(path.fun, "/recover_ini_par", tempo.code, ".pdf")) # remove the pdf file
}
}else{
# test if X11 can be opened
......@@ -6258,6 +6269,7 @@ return(output)
 
 
######## fun_gg_strip() #### ggplot2 stripchart + mean/median
######## fun_gg_dot() #### ggplot2 categorial dotplot + mean/median
 
 
######## fun_gg_violin() #### ggplot2 violins
......@@ -8675,7 +8687,7 @@ output <- paste0("NO WARNING REPORTED", ifelse(is.null(text_fun), "", " "), text
output <- NULL
}
options(warn = warn.options.ini) # restore initial setting
return(output)
return(output) # do not use cat() because the idea is to reuse the message
}
 
 
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment