EDIT to correct incorrect previous answer
After loading, loadNamespace looks for a hook function named .onLoad and calls it. The loadNamespace functions loadNamespace usually called implicitly when the library used to load the package. However, sometimes you can be useful for calling these functions directly. So the following (essentially your code) works for me under the Windows platform.
.onLoad <- function(libname, pkgname ) { if(.Platform$OS.type == "windows") print("windows") else print("others") }
Then you test it using:
loadNamespace("loadpkg") [1] "windows" <environment: namespace:loadpkg>
Note that you can use the same thing with the library , but before you do this, you must unload namespace (I think it checks to see if the package is loaded and does not call all interceptors):
unloadNamespace("loadpkg") library("loadpkg") [1] "windows"
do not use it, it is a wrong decision
You must initialize the function parameters:
.onLoad <- function(libname = find.package(pkg_name), pkgname = pkg_name){ if(.Platform$OS.type == "windows") {
agstudy
source share