[R-pkg-devel] Workflow for Javascript in package?

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Jun 1 16:29:33 CEST 2020

On 01/06/2020 9:15 a.m., Bryan Hanson wrote:
> Duncan, I don’t think it is a particularly clever or efficient example, 
> but my package exCon does some of what you describe.  Additional 
> disclaimer: I’m not very good at serious Javascript, and find the 
> scoping rules challenging.  Even so, exCon works pretty well on large 
> data sets.  But you may be more interested in the infrastructure aspects.

Thanks!  I hadn't thought of using js::uglify_optimize().

I'd like to do the minification during package install rather than when 
used, and this appears to work in the R source code (at top level):

text <- 
package = "rgl"))

if (requireNamespace("js", quietly = TRUE))
   text <- js::uglify_optimize(text)

writeLines(text, file.path(system.file("htmlwidgets/lib/rglClass", 
package = "rgl"), "rglClass.js"))


I'm not completely sure this is supported/allowed, though I don't see a 
CRAN rule to disallow it.

Now I can work on splitting up the big file, and doing a somewhat more 
complicated install of rglClass.js.

Duncan Murdoch

> https://cran.r-project.org/package=exCon
> The gathering of separate .js files, minifying and deployment are 
> handled in the main function exCon.R.  Javascript  and html files in 
> inst/extdata.
> Bryan
> ****************
> Prof. Bryan Hanson (emeritus)
> Dept of Chemistry & Biochemistry
> DePauw University
> Greencastle IN 46135 USA
> Web: academic.depauw.edu/~hanson/index.html 
> <http://academic.depauw.edu/~hanson/index.html>
> Repo: github.com/bryanhanson <http://github.com/bryanhanson>
> Nerdy Blog: ChemoSpec.org <http://ChemoSpec.org>
> The Twit: @ProfBryanHanson
> I’m usually @ -4 GMT/UTC
>> On Jun 1, 2020, at 7:44 AM, Duncan Murdoch <murdoch.duncan using gmail.com 
>> <mailto:murdoch.duncan using gmail.com>> wrote:
>> The rgl package includes a large amount of Javascript source to handle 
>> the display of output in browsers using rglwidget().  Currently this 
>> is mostly in one big file 
>> (inst/htmlwidgets/lib/rglClass/rglClass.src.js), but I'd like to make 
>> some improvements:
>> - splitting it into separate files with related functions
>> - automatically "compiling" it into a single file stripped of white 
>> space and comments, for faster loading.
>> Unfortunately, I have no other experience writing a Javascript 
>> library, so I really don't know what I'm doing.  Can anyone point me 
>> to other R packages containing htmlwidgets that do this "properly", or 
>> point to instructions for the standard workflow for Javascript library 
>> development outside of R that I could adapt?
>> Duncan Murdoch
>> ______________________________________________
>> R-package-devel using r-project.org <mailto:R-package-devel using r-project.org> 
>> mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel

More information about the R-package-devel mailing list