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

Duncan Murdoch murdoch.duncan at gmail.com
Sun Aug 16 01:12:28 CEST 2015


On 15/08/2015 2:36 AM, Dean Attali wrote:
> 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'
>>    All declared Imports should be used.
> 
> 
> 
> 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
>> #' @export
>>  shine <- function() {
>>    shiny::runApp(system.file("shiny", package = "testpkg"))
>>  }
> 
> 
> 
> And this is an example of a dumb app in the inst/shiny location:
> 
> shiny::shinyApp(
>>    ui = shiny::fluidPage(
>>      DT::dataTableOutput("table")
>>    ),
>>    server = function(input, output, session) {
>>      output$table <- DT::renderDataTable(mtcars)
>>    }
>>  )
> 
> 
> 
> 
> 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?

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



More information about the R-package-devel mailing list