Using the JS include statement

You can easily include one script file into another in RKWard plugins. The value of this becomes immediately obvious, if some sections of your JS code are similar across plugins. You can simply define those sections in a separate .js file, and include this in all the plugin .js files. For example, as in:

// this is a file called "common_functions.js"

function doCommonStuff () {
	// perhaps fetch some options, etc.
	// ...
	comment ("This is R code you want in several different plugins\n");
	// ...
}
	
// this is one of your regular plugin .js files

// include the common functions
include ("common_functions.js");

function calculate () {
	// do something
	// ...

	// insert the common code
	doCommonStuff ();
}
	

Note that sometimes it is even more useful to reverse this, and define the skeleton of preprocess(), calculate(), and printout() functions is a common file, and make these call back for those part which are different across plugins. E.g.:

// this is a file called "common_functions.js"

function calculate () {
	// do some things which are the same in all plugins
	// ...

	// add in something that is different across plugins
	getSpecifics ();

	// ...
}
	
// this is one of your regular plugin .js files

// include the common functions
include ("common_functions.js");

// note: no calculate() function is defined in here.
// it in the common_functions.js, instead.

function getSpecifics () {
	// print some R code
}
	

One issue you should be aware of when using this technique is variable scoping. See the JS manual on variable scopes.

This technique is heavily used in the distribution plot and distribution CLT plot plugins, so you may want to look there for examples.