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

Dean Attali daattali at gmail.com
Sat Aug 15 08:36:08 CEST 2015


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?

---
http://deanattali.com

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list