Skip to content

[R-pkg-devel] Listing a package in "Imports:" when it's used outside of "R" directory

4 messages · Dean Attali, Dirk Eddelbuettel, Duncan Murdoch

#
It seems like if a package is declared under the "Imports:" field in
the DESCRIPTION
file, and that package is not used in any code in the R directory, then I
get an error when doing a R CMD CHECK

 Namespace in Imports field not imported from: 'DT'
It certainly makes sense why this is regarded as an error, but I'm running into
a case where I think this should be allowed, and wanted to get your opinion
on whether what I'm doing seems strange or if this error should be
revisited.

Suppose I have a package that implements some analysis pipeline. In order to
make it more accessible and useable, I want to include a Shiny app that uses
the package code.  I place the Shiny app inside the directory "inst/shiny",
and I export a function called "shine" which simply runs the app.  For
example, this could be my shine function:

#' Run the Shiny app
And this is an example of a dumb app in the inst/shiny location:

shiny::shinyApp(
Since the Shiny app is an integral part of the package, and the app uses the
"DT" package, I want to place DT under the Imports: field. But then I ran
into the above error.

I know I can get rid of the problem by placing the entire shiny app in the R
folder, but it's a large app and it seems like separating it and having it
under inst/shiny makes more sense.

What would be the correct solution here?

---
http://deanattali.com
#
On 14 August 2015 at 23:36, Dean Attali wrote:
| Since the Shiny app is an integral part of the package, and the app uses the
| "DT" package, I want to place DT under the Imports: field. But then I ran
| into the above error.

The code checkers are heuristics.  They cannot get everything right.

If this is what you want, why not make it so -- maybe by adding an 'empty'
call into a DT function not used.  Eg

     R/ignoreme.R

containing

     nevercalled <- function(filename) {
          ignored <- data.table::fread(filename)
     }

should do.
 
| I know I can get rid of the problem by placing the entire shiny app in the R
| folder, but it's a large app and it seems like separating it and having it
| under inst/shiny makes more sense.

Why?  It is still in the package.  Maybe make the shiny app a package itself
and add Suggests: on it?
 
Dirk
#
I'll go with your suggestion to make a dummy function, thanks Dirk

---
http://deanattali.com
On 15 August 2015 at 05:35, Dirk Eddelbuettel <edd at debian.org> wrote:

            

  
  
#
On 15/08/2015 2:36 AM, Dean Attali wrote:
If you're not importing it, then don't list it as an import.

"Suggests" sounds closer to what you want, so you could use that, but
then your package will fail if a user installs it without suggested
packages.

"Depends" is generally a bad idea.

So use "Imports", but do import something.

Duncan Murdoch