0

Setup:

  • I'm editting the body of a function foo.bar()in my own package MyPkg.
  • I launch an R session in the root of the package (where DESCRIPTION sits).
  • For good measure, I start cleanly

    devtools::reload()

  • To confirm which version of foo.bar in MyPkg I'd be running I call:

    find("foo.bar")

and get:

[1] ".GlobalEnv"

This means that when I call foo.bar I'd be calling the function installed for my user account.

It's obscure to me how MyPkg got installed for my user account (or why it's necessary), possibly just calling devtools::reload() or devtools::test() did that.

How do I specify that I'd like to call the freshest version of a given function, from the current <root>/R folder?

Vrokipal
  • 784
  • 5
  • 18
  • `devtools::load_all()` should do the trick. – clemens Mar 14 '18 at 11:07
  • @clemens After modifying a function `foo.bar` in either `MyPkg/R` or in `MyPkg/tests/testthat`, `find("foo.bar")` returns two places (`[1] ".GlobalEnv" "package:MyPkg"`). Now calling `foo.bar()` picks up the stale version. Any suggestions to remove the one in ".GlobalEnv"? (should it be there in the first place?) – Vrokipal Mar 14 '18 at 14:44
  • Use `rm(foo.bar)` – clemens Mar 14 '18 at 15:29
  • @clemens Thanks. Please add as an answer so I can mark it as such. – Vrokipal Mar 14 '18 at 16:31

1 Answers1

0

You can use load_all() from devtools which loads a package that's in development and allows you to use it (e.g. its functions) as if it was installed and loaded.

If your current working directory is the root of your package, just type

devtools::load_all()

If the root is not in your current working directory, pass the absolute path to the root as an argument:

devtools::load_all('/absolute/path/to/MyPkg')

To remove functions that you have defined in your global environment, use rm(), e.g. rm(foo.bar)

clemens
  • 6,653
  • 2
  • 19
  • 31