How do I get node or process id when using doParallel?

The foreach package doesn't provide any support for a node id or node name, but R has the "sys.info" function, so you could use:

foreach(i = 1:12, .combine=c) %dopar% {
  Sys.info()[['nodename']]
}

To create a unique worker id, you can combine the node name with the process id of the worker:

foreach(i = 1:12, .combine=c) %dopar% {
  paste(Sys.info()[['nodename']], Sys.getpid(), sep='-')
}

After a lot of trial and error, I found the following to work:

foreach(i = 1:12, .combine=c) %dopar% {
  Sys.getpid()
}

This gives a unique process ID for each of the nodes, which can be used as the node id.