Execute a function from package after doing library(pkg)

女生的网名这么多〃 提交于 2019-12-01 01:02:06

问题


Hi I have a package with a functions that makes a gui with gWidgets, is there a way I can get this to be executed on package load so the interface comes up straight away.

I thought something like this:

.OnAttach <- function(libname, pkgname){
  gui()
}

would work, but I'm still learning about hooks, and the events during package load and unload, and R environment stuff.

EDIT:

This is what I currently have in my zzz file:

.onLoad <- function(libname = find.package("GspeEaR"), pkgname = "GspeEaR") {
  gui()
}

Thanks,

Ben W.


回答1:


I think you want .onLoad which you dump in a .R file called zzz.R (traditionally). Here's an example where I've used this: github.com/trinker/gmailR/blob/master/R/zzz.R



来源:https://stackoverflow.com/questions/14926672/execute-a-function-from-package-after-doing-librarypkg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!