Hi this is a question which i am not sure how to frame.
I am running R from a remote server. My access to the remote server is via ssh@username and so on. After i access i have a command prompt which i invoke R and i am comfortable working on R.
Question 1 I have a large network (100k nodes) and would like to do community detection and would like to run it in the background such that if i close my terminal its keeps running until its finished saves the result in my R working directory.
I have tried using nohup R & but i am not sure the process completed successful.
Question 2 If i manage to implement Question 1, how could i continue to use R to perform other task? and
Question 3 How do i check the task in Q1 is still running.
my attempt on a script looks like this
#!/usr/bin/env Rscript
library(igraph)
library(data.table)
edgebetween <- function(x) {
simplify(x, remove.multiple = F, remove.loops = T)
edge.betweenness.community(x, directed = T)
}
community.a.g3 <- edgebetween(a.g3)
i have saved the script in my working director as a.R
and used at the command prompt after changing to my working directory chmod +x a.R nohup ./a.R &
What would i need to correct. Thanks
The callr package uses processx to start another R process, and run R code in it, in the foreground or background.
Use job::job() to run chunks of R code in an RStudio job instead of the console. This frees your console while the job(s) go brrrrr in the background. By default, the result is returned to the global environment when the job completes.
If you're using R from the command line instead of from within RStudio, you need to use Ctrl + C instead of Esc to cancel the command. This applies to Mac users as well!
To run the entire document press the Ctrl+Shift+Enter key (or use the Source toolbar button).
You want to execute R in "batch" mode. See ( https://stat.ethz.ch/R-manual/R-devel/library/utils/html/BATCH.html )
The command below is an example from those docs. The "&" says "run this separate from the user's login session" so when you log out, it continues to run.
R CMD BATCH [options] infile [outfile] &
You can also use nohup as discussed here ( http://streaming.stat.iastate.edu/wiki/index.php/Running_Jobs_in_the_Background )
nohup R CMD BATCH ./myprog.R &
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With