In foreach package, you can write the codes which are run not only in parallel but also in sequence. And, these are as following.

library(foreach)#we get result as listforeach(i = 1:3) %do% {sqrt(i)}#we get result as vector with using .combine="c" optionforeach(i = 1:3,.combine = "c") %do% {sqrt(i)}#if a result is "vector",we can get it as matrix with using .combine="cbind" optionforeach(i = 1:3,.combine = "cbind") %do% {letters[1:4]}#if you define a function,you can use it as .combine option#I wrote my function as returning same result that specify .combine="c"
MyFunc <- function(x,y)c(x,y)foreach(i = 1:3, .combine = "MyFunc") %do% {sqrt(i)}

Now, We are ready to compute things in parallel. It is easy for us to do that by foreach package. You only have to change "%do%" into "%dopar%". I compared the performance of parallel comutation to single computation as following.