我对R和它的包系统都很陌生,我刚刚编写了我的第一个包,目的是将它与OpenCPU一起使用。
在执行此功能时:
#' Create a PNG which shows interpolated senseMap Data
#'
#' @export
#' @import jsonlite
#' @import sp
#' @import gstat
#' @import rgeos
#' @import maptools
#' @param JSON
inteRidwTest <- function(input){
### JSON to data.frame ###
oSeM_df <- input
### data.frame to spatialPointsDataFrame ###
coordinates(oSeM_df) =~longitude+latitude
### adding CRS to the data ###
proj4string(oSeM_df)="+proj=longlat +datum=WGS84"
project_df=spTransform(oSeM_df, CRS("+proj=longlat +datum=WGS84"))
### creating a bounding box ###
bbox <- bbox(oSeM_df)
### creating a grid based on the bbox ###
x.range <- as.numeric(c(floor(bbox[1]), ceiling(bbox[3]))) # min/max longitude of the interpolation area
y.range <- as.numeric(c(floor(bbox[2]), ceiling(bbox[4])))# min/max latitude of the interpolation area
grd <- expand.grid(x = seq(from = x.range[1], to = x.range[2], by = 0.1), y = seq(from = y.range[1], to = y.range[2], by = 0.1))
coordinates(grd) <- ~x + y
gridded(grd) <- TRUE
grdSp <- as(grd, "SpatialPolygons")
### adding CRS to grid ###
proj4string(grdSp)="+proj=longlat +datum=WGS84"
grd_df=spTransform(grdSp, CRS("+proj=longlat +datum=WGS84"))
### setting up basegrid for the png ###
grdSp.union <- unionSpatialPolygons(grd_df, rep("x", length(slot(grd_df,"polygons"))))
llGRD <- GE_SpatialGrid(grdSp.union)
llGRD_in <- over(llGRD$SG, grdSp.union)
llSGDF <- SpatialGridDataFrame(grid = slot(llGRD$SG,"grid"), proj4string = CRS(proj4string(llGRD$SG)), data = data.frame(in0 = llGRD_in))
llSPix <- as(llSGDF, "SpatialPixelsDataFrame")
### IDW ###
llSPix$pred <- idw(value ~ 1, oSeM_df, llSPix)$var1.pred
return(llSPix$pred)
# ### create the png ###
# png(file = "idw.png", width = llGRD$width,height = llGRD$height, bg = "transparent")
# par(mar = c(0, 0, 0, 0), xaxs = "i", yaxs = "i")
# image(llSPix, "pred", col = bpy.colors(20, alpha=0.7))
# dev.off()
}引发以下错误:
未找到OpenCPU error HTTP400对象“rgeos” In call: get("rgeos",envir = .MAPTOOLS_CACHE)
在尝试在本地使用此包和函数时,也会引发相同的错误。如果在我的inteRsense包之前安装并添加了rgeos包,它将按预期工作。
错误似乎连接到我的包导入的rgeos和maptools包,我想在使用我的包时更改这些包的导入顺序。但我不知道如何在命名空间文件中这样做:
# Generated by roxygen2: do not edit by hand
export(helloWorld)
export(inteRidw)
export(inteRidwTest)
import(gstat)
import(jsonlite)
import(maptools)
import(rgeos)
import(sp)因此,我想我这里的问题是:如何更改R包中的命名空间文件?但我真的很感激你的帮助。
发布于 2016-03-08 10:00:59
如何更改R包中的命名空间文件?
若要更改R包中的命名空间文件,必须:
问题是,更改将是本地的,您必须自己分发修改后的包。
在这种情况下,最好的解决方案可能是与包的维护人员联系,看看它是否能够修复问题并更新cran存储库中的包。
然而,我正经历着同样的问题。我知道这个错误:
Error in get("rgeos", envir = .MAPTOOLS_CACHE) : object 'rgeos' not found当我正在开发的包调用maptools函数‘unionSpatialPoly龙’时。我正在处理的包同时导入了maptools和rgeos包,但仍然失败。如果maptools包是由用户手动加载的,那么一切都可以正常工作。
因此,另一个临时解决方案是在加载包后加载maptools包。
更新
我编辑了我正在处理的包的描述文件。我将'maptools‘包从“导入”字段移到“依赖”字段,问题似乎就消失了!
https://stackoverflow.com/questions/35587111
复制相似问题