我是新手,对于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()
}
使用此输入:https://gist.githubusercontent.com/mdragunski/643a8557a4a0e37d30a1/raw/02d26c3ce83ee0c0c704b7c53984c640002c331f/oSeM-Data-processed.json,将会抛出以下错误:
OpenCPU错误HTTP 400对象'rgeos'未找到 在调用中:get("rgeos", envir = .MAPTOOLS_CACHE)
当尝试本地使用此软件包和函数时,也会抛出相同的错误。如果在我的inteRsense软件包之前安装并添加了rgeos软件包,则可以正常使用。
该错误似乎与软件包rgeos和maptools相关,这两个软件包由我的软件包导入,我想在使用我的软件包时更改导入这些软件包的顺序。但是我无法弄清楚如何在NAMESPACE文件中实现此操作。
# 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软件包中的NAMESPACE文件?但是我真的很感谢任何帮助。