Skip to content

Commit

Permalink
HELP: Add raster and 'RasterLayer' to the list of object that may hav…
Browse files Browse the repository at this point in the history
…e external pointers [#453] [ci skip]
  • Loading branch information
HenrikBengtsson committed Dec 7, 2020
1 parent 8599a14 commit b82ce63
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion vignettes/future-4-non-exportable-objects.md.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ _If you identify other cases, please consider [reporting](https://github.com/Hen
**keras** | keras.engine.sequential.Sequential (`externalptr`)
**magick** | magick-image (`externalptr`)
**ncdf4** | ncdf4 (custom reference; _non-detectable_)
**raster** | RasterLayer (`externalptr`; _not all_)
**Rcpp** | NativeSymbol (`externalptr`)
**reticulate** | python.builtin.function (`externalptr`), python.builtin.module (`externalptr`)
**rJava** | jclassName (`externalptr`)
Expand Down Expand Up @@ -142,7 +143,7 @@ the future expression

#### Package: magic

[magick](https://cran.r-project.org/package=magick) provides an R-level API for ImageMagick to work with images. When working with this API, the images are represented internally as external pointers of class 'magick_image' that cannot be be exported to another R process, e.g.
The [magick](https://cran.r-project.org/package=magick) package provides an R-level API for ImageMagick to work with images. When working with this API, the images are represented internally as external pointers of class 'magick_image' that cannot be be exported to another R process, e.g.
```r
library(future)
plan(multisession)
Expand All @@ -167,6 +168,30 @@ we'll see that this is caught even before attempting to run this in parallel;
```


#### Package: raster

The [raster](https://cran.r-project.org/package=raster) package provides methods for working with spatial data, which are held in 'RasterLayer' objects. Not all but some of these objects use an external pointer. For example,

```r
library(future)
plan(multisession)

library(raster)
r <- raster(system.file("external/test.grd", package = "raster"))
tf <- tempfile(fileext = ".grd")
s <- writeStart(r, filename = tf, overwrite = TRUE)

f <- future({
print(dim(r))
print(dim(s))
})
Error: Detected a non-exportable reference ('externalptr') in one of the
globals ('s' of class 'RasterLayer') used in the future expression
```

Note that it is only the RasterLayer object `s` that carries an external pointer and cannot be passed on to an external worker. In constract, RasterLayer object `r` does not have this problem and would be fine to pass on to a worker.


#### Package: Rcpp

Another example is [Rcpp](https://cran.r-project.org/package=Rcpp) , which allow us to easily create R functions that are implemented in C++, e.g.
Expand Down

0 comments on commit b82ce63

Please sign in to comment.