pforeach: An easy way to parallel processing in R

並列処理を容易に行うためのパッケージ

> library(pforeach)

バージョン: 1.3


関数名 概略
cols Iterator for data frame by column
icols Iterator for column number of a data frame
irows Iterator for row number of a data frame
npforeach Non-Parallelized pforeach
pforeach pforeach
rows Iterator for data frame by row
stopImplicitCluster2 Stop implicit cluster
update Reinstall pforeach package

npforeach

非並列化計算

> npforeach(i = 1:3)({
+   rnorm(1)
+ })
[1] 1.4984319 0.5493388 0.2416337

pforeach

> pforeach(i = 1:100)({
+   i + 1
+ })
foreach: simple, scalable parallel programming from Revolution Analytics
Use Revolution R for scalability, fault tolerance and more.
http://www.revolutionanalytics.com

Attaching package: 'assertthat'

The following object is masked from 'package:evaluate':

    is.error

Loading required package: rngtools
Loading required package: pkgmaker
Loading required package: registry

Attaching package: 'pkgmaker'

The following object is masked from 'package:assertthat':

    is.dir

The following object is masked from 'package:base':

    isNamespaceLoaded


Attaching package: 'LearnBayes'

The following object is masked from 'package:dplyr':

    regroup


Attaching package: 'lattice'

The following object is masked from 'package:spatstat':

    panel.histogram


Attaching package: 'chron'

The following object is masked from 'package:foreach':

    times

polyclip 1.3-2

Attaching package: 'colorspace'

The following object is masked from 'package:spatstat':

    coords

The following object is masked from 'package:raster':

    RGB

-------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
-------------------------------------------------------------------------

Attaching package: 'plyr'

The following objects are masked from 'package:dplyr':

    arrange, count, desc, failwith, id, mutate, rename, summarise,
    summarize


Attaching package: 'xtable'

The following object is masked from 'package:maptools':

    label


Attaching package: 'scales'

The following objects are masked from 'package:spatstat':

    ordinal, rescale

This is mgcv 1.8-7. For overview type 'help("mgcv-package")'.
Run options(error = DYM) to enable 'Did you mean' feature
deldir 0.1-9
Loading required package: iterators
Loading required package: parallel

Attaching package: 'MASS'

The following object is masked from 'package:spatstat':

    area

The following objects are masked from 'package:raster':

    area, select

The following object is masked from 'package:dplyr':

    select


Attaching package: 'tools'

The following object is masked from 'package:XML':

    toHTML


Attaching package: 'munsell'

The following object is masked from 'package:colorspace':

    desaturate

Loading required package: bitops

Attaching package: 'igraph'

The following object is masked from 'package:stringr':

    %>%

The following object is masked from 'package:LearnBayes':

    sir

The following objects are masked from 'package:tigris':

    %>%, blocks

The following objects are masked from 'package:spatstat':

    diameter, edges, vertices

The following object is masked from 'package:raster':

    union

The following objects are masked from 'package:dplyr':

    %>%, as_data_frame, groups, union

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:magrittr':

    %>%

The following object is masked from 'package:base':

    union


Attaching package: 'boot'

The following object is masked from 'package:lattice':

    melanoma

The following object is masked from 'package:LearnBayes':

    darwin

The following object is masked from 'package:spatstat':

    envelope


Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric


Attaching package: 'lubridate'

The following object is masked from 'package:igraph':

    %--%

The following object is masked from 'package:plyr':

    here

The following objects are masked from 'package:chron':

    days, hours, minutes, seconds, years

The following objects are masked from 'package:data.table':

    hour, mday, month, quarter, wday, week, yday, year

rgdal: version: 1.0-4, (SVN revision 548)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
 Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgdal/gdal
 Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
 Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rgdal/proj
 Linking to sp version: 1.1-1 
rgeos version: 0.3-11, (SVN revision 479)
 GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921 
 Linking to sp version: 1.1-0 
 Polygon checking: TRUE
  [1]   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
 [18]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35
 [35]  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52
 [52]  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69
 [69]  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86
 [86]  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101
> pforeach(i = 1:150)({
+   iris[i, ] %>% dplyr::select(-Species) %>% sum
+ })
  [1] 10.2  9.5  9.4  9.4 10.2 11.4  9.7 10.1  8.9  9.6 10.8 10.0  9.3  8.5
 [15] 11.2 12.0 11.0 10.3 11.5 10.7 10.7 10.7  9.4 10.6 10.3  9.8 10.4 10.4
 [29] 10.2  9.7  9.7 10.7 10.9 11.3  9.7  9.6 10.5 10.0  8.9 10.2 10.1  8.4
 [43]  9.1 10.7 11.2  9.5 10.7  9.4 10.7  9.9 16.3 15.6 16.4 13.1 15.4 14.3
 [57] 15.9 11.6 15.4 13.2 11.5 14.6 13.2 15.1 13.4 15.6 14.6 13.6 14.4 13.1
 [71] 15.7 14.2 15.2 14.8 14.9 15.4 15.8 16.4 14.9 12.8 12.8 12.6 13.6 15.4
 [85] 14.4 15.5 16.0 14.3 14.0 13.3 13.7 15.1 13.6 11.6 13.8 14.1 14.1 14.7
 [99] 11.7 13.9 18.1 15.5 18.1 16.6 17.5 19.3 13.6 18.3 16.8 19.4 16.8 16.3
[113] 17.4 15.2 16.1 17.2 16.8 20.4 19.5 14.7 18.1 15.3 19.2 15.7 17.8 18.2
[127] 15.6 15.8 16.9 17.6 18.2 20.1 17.0 15.7 15.7 19.1 17.7 16.8 15.6 17.5
[141] 17.8 17.4 15.5 18.2 18.2 17.2 15.7 16.7 17.3 15.8

参考