-
-
Save ngoet/c61435adf8997815b60394f637c4e740 to your computer and use it in GitHub Desktop.
Combining R and Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set up log file | |
logfile_name <- gsub('-| |:','_',paste('logfile_',Sys.time(),'.log',sep='')) | |
log_file <- file(logfile_name) | |
# function | |
execute_script <- function(print_message,script_name,type="R",input_params=NULL,numCores=NULL){ | |
message(print_message) | |
log_file <- file(logfile_name, open = 'a') | |
cat(paste('\n\nExecuting ',script_name,' script (start time: ',Sys.time(),')',sep=''), file = log_file,append = TRUE) | |
close(log_file) | |
if(type=="R"){ | |
execution_time <- round(system.time({source(script_name)})[3]/60,digits=2) | |
}else{ | |
execution_time <- round(system.time({system(paste('python3',script_name,input_params,sep=' '))})[3]/60,digits=2) | |
} | |
log_file <- file(logfile_name, open = 'a') | |
cat(paste('\n',script_name, ' script successfully run. Execution time: ',execution_time," minutes",sep=''), file = log_file,append = TRUE) | |
close(log_file) | |
message(paste('\n',script_name, ' script successfully run. Execution time: ',execution_time," minutes",sep='')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment