Create a package that depends on other packages

1

Personal I'm creating a package with some functions one of them depends on another package, as "gives the signal" for the R understand and install this package? The package I depend on is raster .

a = matrix(c(0,0,2,0,2,2,0,2), byrow = T, ncol = 2)
b = list(matrix(c(0.5, 0 ,1 , 1, 1.5, 0), ncol = 2, byrow = T))

polygon.intersection <- function(polygon1,polygon2){
  polygon11 = as(polygon1, "gpc.poly")
  polygon22 = as(polygon2, "gpc.poly")
  res = intersect(polygon11, polygon22)
  if(is.na(get.bbox(res)$x[[1]])) res = matrix(c(0,0,0,0), ncol = 2)

  else res1 = as(res, "matrix")
  res1
}
polygon.intersection(a,b)
    
asked by anonymous 11.06.2016 / 00:37

1 answer

2

In the directory where your package code is located, there should be a metadata file named DESCRIPTION . In this file, one of the fields that can be included is Imports , which indicates that your package depends on other package (s) to work.

For example, your file could contain the following:

Imports:
    raster,
    sp

See that your package does not install the other packages by itself, but these dependencies are read when someone runs install.packages() and all imported packages are also installed.

I recommend reading the Hadley site for more details on creating packages.

    
11.06.2016 / 00:57