Learn R Programming

rgl (version 1.2.8)

makeDependency: Process Javascript for HTML dependency

Description

A utility function to help in development of internal Javascript code, this function processes the Javascript to minify it and report on errors and bad style.

Usage

makeDependency(name, src, script = NULL, package, 
               version = packageVersion(package),
               minifile = paste0(basename(src), ".min.js"),
               debugging = FALSE, ...)

Value

An object that can be included in a list of dependencies passed to htmltools::attachDependencies.

Arguments

name, src, script, package, version, ...

Arguments to pass to htmltools::htmlDependency.

minifile

Basename of minified file.

debugging

See details below.

Author

Duncan Murdoch

Details

This is a utility function used by RGL to process its Javascript code used when displaying rglwidget values. It may be helpful in other packages to use in their own installation.

If the js package version 1.2 or greater is installed, the Javascript code will be minified and stored in the file named by minifile in the src directory. Syntax errors in the code will stop the process; unused variables will be reported.

If debugging is TRUE, the locations of Javascript syntax errors will be reported, along with hints about improvements, and the original files will be used in the dependency object that is created.

If debugging is FALSE (the default), the minified file will be used in the dependency object, hints won't be given, and syntax errors will lead to an uninformative failure to minify.

Examples

Run this code
if (FALSE) {
# This is a slightly simplified version of the code used to 
# produce one of the dependencies for rglwidget().  
# It writes to the system library copy of rgl so 
# has been marked not to run in the example code.

makeDependency("rglwidgetClass", 
               src = "htmlwidgets/lib/rglClass",
               script = c("rglClass.src.js",
                          "utils.src.js",
                          "buffer.src.js",
                          "subscenes.src.js",
                          "shaders.src.js",
                          "textures.src.js",
                          "projection.src.js",
                          "mouse.src.js",
                          "init.src.js",
                          "pieces.src.js",
                          "draw.src.js",
                          "controls.src.js",
                          "selection.src.js",
                          "rglTimer.src.js",
                          "pretty.src.js",
                          "axes.src.js",
                          "animation.src.js"),
               stylesheet = "rgl.css",
               package = "rgl",
               debugging = isTRUE(as.logical(Sys.getenv("RGL_DEBUGGING", "FALSE"))))
}

Run the code above in your browser using DataLab