package development use and build workflow

I have partially built a package in R.
I have 2 instances of Rstudio running. I have the package open in one instance and a project i am working on in another. As i am working on my project i find that i need to add additional functionality to the package. So i go to the package, add the functionality, build it, then return the project i am working on. This additional functionality is not available to me in my project. I find i have to restart R each time (Ctrl + shift + F10) but i lose everything in my environment. Of course i could save the environment before closing, but i still have to close Rstudio. I am finding this frustrating and time consuming

I am sure i am approaching this all wrong so what is the best way to be deal with this? thanks

Three options:

  1. Save your environment, restart the R session, and reload the environment.

    # Ctrl + Shift + F10

    Make sure to reload any packages.

  2. Only remove the changed package:

     # replace "mypackage" with your package's name
    detach("package:mypackage", unload = TRUE)
  3. What I do: accept it as a pain. If you keep your work in scripts, you can just rerun those. Or if you're the "free explorer" type, then you can re-run the commands from the history pane. Hopefully it won't take too long. I like to use this kind of time as an excuse to browse these forums.

Cool thanks @nwerth. So i wasn't using library to load in the package rather referencing by namespace. So if i use


then reference the changed package i see the change. This works.

thanks a lot! appreciate the response

1 Like

Glad to hear you got it working!

Would you mind marking your use of unloadNamespace as the solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.