23

I have an R package that I've been building in RStudio, let's called it my_pkg. When I run devtools::load_all(".") within RStudio (specifically using the Ctrl + Shift + L shortcut), I get the following message:

Loading my_pkg
Warning messages:
1: character(0) 
2: character(0) 
3: character(0) 
4: character(0) 
5: character(0)

All of the functions in the package work fine. My NAMESPACE and DESCRIPTION files are complete with no syntax errors. When I run ?my_pkg, however, the help file does not match the specifications provided in the DESCRIPTION file. When I remove the Imports from DESCRIPTION, there is no more character(0) warning message. Of course, I need those imports. When I change Imports to Suggests, there is character(0) warning message.

Here is the description file content, with some stuff changed to protect IP.

Package: scoutdroid
Title: This is where the title is.
Version: 0.1
Authors@R: "Ben Hanowell <benjamin.hanowell@redfin.com> [aut, cre]"
Description: This is where the description is.
Depends:
    R (>= 3.1.0)
Imports:
    dplyr,
    lubridate,
    mboost,
    randomForestSRC,
    RODBC,
    stringr
License: file LICENSE
LazyData: true

And here is NAMESPACE.

# Generated by roxygen2 (4.0.1): do not edit by hand

import(RODBC)
import(dplyr)
import(lubridate)
import(mboost)
import(parallel)
import(randomForestSRC)
import(stringr)

When I use the RStudio Build & Reload button in the Build tab, I get the following warnings:

** preparing package for lazy loading

Warning: replacing previous import by 'lubridate::intersect' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::setdiff' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::union' when loading 'scoutdroid'

edit Added some more details to help folks understand what might be going on.

edit 2 I also added the DESCRIPTION file, although I don't provide the full package, which is proprietary.

edit 3 Added NAMESPACE.

edit 4 Added warnings that occur when using RStudio Build & Reload button in the Build tab.

Brash Equilibrium
  • 1,357
  • 4
  • 14
  • 35
  • Is your package on github – Dason Sep 29 '14 at 16:21
  • No. It is proprietary. *edit* It is on Bitbucket, but access is private. – Brash Equilibrium Sep 29 '14 at 16:48
  • 1
    Well good luck. Maybe you could try making a minimal reproducible example. – Dason Sep 29 '14 at 17:27
  • 1
    The last time [something similar happened](http://stackoverflow.com/questions/13085481/namespace-dependencies-not-required/13261139#comment18121469_13261139) it turned out there was a problem with the DESCRIPTION file afterall – GSee Sep 30 '14 at 00:19
  • If it is something wrong with the DESCRIPTION file, then why does the problem go away when I replace Imports with Suggests? – Brash Equilibrium Sep 30 '14 at 00:29
  • 1
    You're using the fact that changing the DESCRIPTION file "fixes" the problem as evidence that there isn't a problem with the DESCRIPTION file? Are you able to build, check, and install the package without using `load_all`? I think seeing the NAMESPACE file would help, but that might be getting too much into your proprietary code. I suggest trying to make a simple package with only one function and see if you can reproduce the problem. – GSee Sep 30 '14 at 00:30
  • # Generated by roxygen2 (4.0.1): do not edit by hand import(RODBC) import(dplyr) import(lubridate) import(mboost) import(parallel) import(randomForestSRC) import(stringr) – Brash Equilibrium Sep 30 '14 at 00:34
  • 2
    I could be totally wrong, but my hunch is that those "warnings" are "replacing previous import" warnings that devtools is trying to suppress. http://stackoverflow.com/a/18403565/967840 – GSee Sep 30 '14 at 00:37
  • You are totally right. I built and reloaded. package::lubridate is the problem. You know how to fix that? – Brash Equilibrium Sep 30 '14 at 00:40
  • 2
    Don't import those functions from lubridate. Use `importFrom` to only import the functions that you actually use. I think @hadley was working on an `@autoimport` tag in roxygen3 that might do this for you, but I don't know the status of roxygen3 or if it's been integrated into RStudio. – GSee Sep 30 '14 at 00:43
  • Tried it. IT WORKED! Thanks @GSee. I believe this is the second time you've saved my tookus this week. – Brash Equilibrium Sep 30 '14 at 00:46
  • @GSee, I would upvote the ever-living crud out of your answer and then check it if you wrote it up. – Brash Equilibrium Sep 30 '14 at 00:52

2 Answers2

25

After some dialoge in the comments, we figured out that the empty warnings that load_all is giving you are actually initiated when loading the package because of function name conflicts.

The issue is that you are importing a function from a package, then overwriting that function. When that happens R throws warnings as you saw when you clicked "Build & Reload" in RStudio:

Warning: replacing previous import by 'lubridate::intersect' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::setdiff' when loading 'scoutdroid'
Warning: replacing previous import by 'lubridate::union' when loading 'scoutdroid'

It looks like load_all may be attempting to muffle those warnings (just a guess) which is why you see character(0) instead of the actual warnings. (These particular warnings are difficult to silence.)

It is generally not a good idea to import an entire package's namespace. You should instead import only the symbols you need. See this post of mine for more.

The solution is to use importFrom instead of import in your NAMESPACE file.

Community
  • 1
  • 1
GSee
  • 48,880
  • 13
  • 125
  • 145
  • 2
    For others comming here, looking for solutions. When you run `devtools::check`, the warnings above will show – adibender Sep 06 '17 at 11:39
2

It can also be due to a broken link in the roxygen2 documentation. For example when you link to a function external to your package with the wrong name, say \link[stringi]{STRI_C} instead of \link[stringi]{stri_c}

Duccio A
  • 1,402
  • 13
  • 27