'Install/update package through a function in that very same package

I realized I probably did something stupid...I created my own package and put it into a Google drive.

I've written a function in that package update_my_package which downloads the tar.gz file from Google drive and then tries to install/update this package with remotes::install_local().

However, this doesn't seem to work, because the package is obviously currently in use when running the update function.

Warning: package ‘my_package’ is in use and will not be installed

I found this one here: https://stackoverflow.com/a/35723153/2725773, but I think it won't work, because I probably can't detach a package from a function within that package.

So anything I can do or will my way just not work?



Solution 1:[1]

Interestingly, installing/updating a package through a function of that package is possible after all. The "trick" was to first detach the package before installing the update, e.g.

update_fun <- function()
{
  detach(package:my_package, unload = TRUE)
  remotes::install_local("my_package")
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 deschen