标签: r-library

如何从同一自定义 R 包函数中调用 3 种不同算法的预测?

我正在开发一个自定义 R 包(它是私有的,不在任何地方托管)。在这个包中,我有一个函数,它采用 xgboost、RandomForest(来自 ranger 函数)和 glmnet 模型,并使用它们来预测新数据集。

每次预测时,我都会使用相同的广义预测函数。如果我没有为函数命名空间,R 就不知道使用哪个库来进行预测。

我得到的错误是:

Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "c('lognet', 'glmnet')" 
Run Code Online (Sandbox Code Playgroud)

如果我手动加载函数,它可以工作,但我知道在 R 库中手动加载包是一个禁忌。

我尝试使用 glmnet::glmnet.predict 等,但这也给了我错误。命名这些预测函数以避免手动加载库的正确方法是什么?

r r-library

5
推荐指数
1
解决办法
921
查看次数

为什么我失去了使用 Mapshot 的能力

我经常使用mapshot来发送交互式地图数据,但最近,虽然我可以用mapview制作我想要的地图,但我无法保存它们。

例子:

map<- mapview(mapdata, zcol = "columnofinterest", burst = TRUE)

mapshot(map, url = paste0(getwd(), "/whatIwanttocallmymap.html"))

File whatIwanttocallmymap_files/PopupTable-0.0.1/popup.css not found in resource path
Error: pandoc document conversion failed with error 99
Run Code Online (Sandbox Code Playgroud)

恐怕我在获取包裹的方式上搞砸了。带有包名称的文件夹出现在我设置为 wd 的区域中,而不是出现在我的 R 库中

感谢您提供的任何帮助/建议

r r-leaflet r-mapview r-library

5
推荐指数
0
解决办法
1418
查看次数

标签 统计

r ×2

r-library ×2

r-leaflet ×1

r-mapview ×1