Skip to content

[R-pkg-devel] Specifying non-C/C++ build-time dependency

6 messages · Andrew Johnson, James Lamb, Wolfgang Viechtbauer +1 more

#
Hi all!

I have an R package which uses several JS scripts/libraries, and I'm trying to configure the build process to minify the JS files at build-time (via my jsutils package: https://cran.r-project.org/web/packages/jsutils/).

My current approach is using a configure script to run the minification, with the jsutils package added as an Import (https://github.com/AUS-DOH-Safety-and-Quality/controlcharts/pull/25). But this adds an additional runtime dependency when it's only needed at build time.

Are there any recommended ways for specifying build-time dependencies when the package doesn't require compilation? My attempts to use the LinkingTo field so far are giving check notes for not having source or include files.

Any suggestions are much appreciated!

Thanks,
Andrew
#
(forgot to CC the list on my previous reply)

Hey Andrew,

To avoid needing to declare the dependency in any context, assuming that
the minification is deterministic and not dependent on any details of the
runtime environment (like CPU architecture), I recommend just doing the
minification in a shell script, Makefile, etc. BEFORE calling `R CMD
BUILD`, then uploading a package to CRAN vendoring already-minified sources.

I think you'll find it's easier that way (and easier for any users who end
up building your package from source).

Cheers,

- James

On Tue, Jan 13, 2026, 11:55?PM Andrew Johnson <
andrew.johnson at arjohnsonau.com> wrote:

            

  
  
#
Hi Andrew,

This is something that came up with the mathjaxr package, which bundles MathJax. Originally it included the minified code, but this was not acceptable as the proper source code, especially for the Debian packages.

So the package then included the unminified code that was minified via a make file on installation if the 'js' package was installed. So 'js' was a suggested package, not required.

Unfortunately, the minification with js no longer works with the most recent version of MathJax (same issue as https://github.com/jeroen/js/issues/5), but since CRAN packages can now be a bit larger (I believe up to 10MB), the minification is no longer a hard requirement to get mathjaxr on CRAN and I removed this step from the most recent version.

But you can grab version 1.8.0 from https://cran.r-project.org/src/contrib/Archive/mathjaxr/ to see how things used to be done.

Best,
Wolfgang
7 days later
#
On 2026-01-14 12:55 a.m., Andrew Johnson wrote:
The rgl package keeps Javascript code deep down within the inst 
directory, and uses R code calling js::uglify_files to minify them.

Remember that building a package entails running every .R file in the R 
directory.  In most cases that just executes function definitions, but 
it can also execute other code involved in building.  So rgl defines a 
function rgl::makeDependency(), then calls things like

   CanvasMatrixDependency <- makeDependency("CanvasMatrix4",
     src = "htmlwidgets/lib/CanvasMatrix",
     script = "CanvasMatrix.src.js",
     package = "rgl",
     debugging = isTRUE(as.logical(Sys.getenv("RGL_DEBUGGING", "FALSE"))))

to minify it and record the information used by htmlwidgets to handle 
dependencies.  The makeDependency() function is exported from rgl, and 
might be useful as a model for the kinds of things you should do.  If 
you're using htmlwidgets, then you might be able to use it as-is.

Duncan Murdoch
4 days later
#
Hi Duncan,

That's perfect, exactly what I was looking for!

Many thanks for the help!
Andrew

-----Original Message-----
From: Duncan Murdoch <murdoch.duncan at gmail.com> 
Sent: Friday, 23 January 2026 5:39 AM
To: Andrew Johnson <andrew.johnson at arjohnsonau.com>; R Package Development <r-package-devel at r-project.org>
Subject: Re: [R-pkg-devel] Specifying non-C/C++ build-time dependency
On 2026-01-14 12:55 a.m., Andrew Johnson wrote:
The rgl package keeps Javascript code deep down within the inst directory, and uses R code calling js::uglify_files to minify them.

Remember that building a package entails running every .R file in the R directory.  In most cases that just executes function definitions, but it can also execute other code involved in building.  So rgl defines a function rgl::makeDependency(), then calls things like

   CanvasMatrixDependency <- makeDependency("CanvasMatrix4",
     src = "htmlwidgets/lib/CanvasMatrix",
     script = "CanvasMatrix.src.js",
     package = "rgl",
     debugging = isTRUE(as.logical(Sys.getenv("RGL_DEBUGGING", "FALSE"))))

to minify it and record the information used by htmlwidgets to handle dependencies.  The makeDependency() function is exported from rgl, and might be useful as a model for the kinds of things you should do.  If you're using htmlwidgets, then you might be able to use it as-is.

Duncan Murdoch
#
You're welcome.  Just noticed one little error in what I wrote:  it's 
"installing" that runs all the code, not "building".

Duncan Murdoch
On 2026-01-26 11:49 p.m., Andrew Johnson wrote: