Title: | Interface to 'Maxima', Enabling Symbolic Computation |
---|---|
Description: | An interface to the powerful and fairly complete computer algebra system 'Maxima'. It can be used to start and control 'Maxima' from within R by entering 'Maxima' commands. Results from 'Maxima' can be parsed and evaluated in R. It facilitates outputting results from 'Maxima' in 'LaTeX' and 'MathML'. 2D and 3D plots can be displayed directly. This package also registers a 'knitr'-engine enabling 'Maxima' code chunks to be written in 'RMarkdown' documents. |
Authors: | Eric Stemmler [aut, cre], Kseniia Shumelchyk [aut], Hans W. Borchers [aut] |
Maintainer: | Eric Stemmler <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.7.0 |
Built: | 2025-03-07 05:04:53 UTC |
Source: | https://github.com/rcst/rim |
Provides an interface to Maxima, a computer algebra system.
maxima.start(restart = FALSE) maxima.stop(engine = FALSE) maxima.get(command) maxima.load(module) maxima.apropos(keystring) maxima.version() maxima.isInstalled() iprint(x) ## S3 method for class 'maxima' print(x, ...) maxima.eval(x, code = FALSE, envir = globalenv())
maxima.start(restart = FALSE) maxima.stop(engine = FALSE) maxima.get(command) maxima.load(module) maxima.apropos(keystring) maxima.version() maxima.isInstalled() iprint(x) ## S3 method for class 'maxima' print(x, ...) maxima.eval(x, code = FALSE, envir = globalenv())
restart |
if FALSE (default), then Maxima is started provided it is not running already. If TRUE starts or restarts Maxima. |
engine |
if FALSE (default), quits the (running) maxima instance and closes the connection, otherwise quits and closes the (running) maxima instance used for the knitr engine. |
command |
character string containing the Maxima command. |
module |
character vector naming the Maxima module (typically a *.mac or *.lisp file) to be loaded. |
keystring |
character vector containing a search term. |
x |
Either a character vector of length 1L or an S3 object of class "maxima" |
... |
other arguments (ignored). |
code |
A logical vector of length 1L, whether to attach the original expression (TRUE) or not (FALSE, default) |
envir |
A environment object. |
Note: You need to install the Maxima software separately in order to make use of this package.
Maxima is set up automatically on attachment via library(rim)
and automatically started when a command is send (if it isn't running already) using maxima.get()
. If environment variable RIM_MAXIMA_PATH is not set, rim will search for the Maxima executable, or use the former otherwise. Using maxima.start()
and maxima.stop()
, one can stop and (re-)start the current Maxima session if needed, e.g. to clear Maxima command and output history.
To send a single command to Maxima and receive the corresponding output use maxima.get()
. This function returns a S3 object of class "maxima". The output is printed by printing the object and will be printed in a format currently set by maxima.options(format)
. The output format can be changed by setting it, e.g. maxima.options(format = "ascii")
. Output labels are printed according to option maxima.options(label)
.
invisibly returns NULL.
Character vector of length 1 of the input command. Depending on whether option "label" is set to TRUE, the corresponding input reference label is printed preceding the input command.
The evaluated R-object
maxima.start()
: (re-)starts Maxima.
maxima.stop()
: Quits Maxima.
maxima.get()
: Executes a single Maxima command provided by command
. If no command ending character (;
or $
is provided, ;
is appended.
maxima.load()
: A wrapper to load a Maxima module named by module
maxima.apropos()
: A wrapper to the Maxima helper function apropos
to lookup existing Maxima functions that match keystring
.
maxima.version()
: Returns the version number of Maxima that is used
maxima.isInstalled()
: Returns TRUE when an installation of Maxima has been detected, otherwise FALSE
iprint()
: Prints the input command of an maxima S3-object returned by maxima.get()
print(maxima)
: Prints the maxima output part of an S3 object returned by maxima.get()
maxima.eval()
: Evaluates the parsed and quoted R-expression which is part of an S3 object returned by maxima.get()
Maintainer: Eric Stemmler [email protected]
Authors:
Kseniia Shumelchyk [email protected]
Hans W. Borchers [email protected]
Useful links:
Report bugs at https://github.com/rcst/rim/issues
if(maxima.isInstalled()) maxima.start(restart = TRUE) if(maxima.isInstalled()) { maxima.start(restart = TRUE) maxima.stop() } if(maxima.isInstalled()) maxima.get("2+2;") if(maxima.isInstalled()) maxima.load("abs_integrate") if(maxima.isInstalled()) maxima.apropos("integrate") maxima.version() maxima.isInstalled() if(maxima.isInstalled()) { a <- maxima.get("2+2;") iprint(a) } if(maxima.isInstalled()) { a <- maxima.get("2+2;") print(a) } if(maxima.isInstalled()) { a <- maxima.get("2+2;") maxima.eval(a) # same maxima.eval("2+2;") # evaluate with data.frame df <- data.frame(x = seq(0, 1, by = 0.1)) maxima.eval("integrate(1 / (1 + x^4), x);", code = TRUE, envir = df) maxima.stop() }
if(maxima.isInstalled()) maxima.start(restart = TRUE) if(maxima.isInstalled()) { maxima.start(restart = TRUE) maxima.stop() } if(maxima.isInstalled()) maxima.get("2+2;") if(maxima.isInstalled()) maxima.load("abs_integrate") if(maxima.isInstalled()) maxima.apropos("integrate") maxima.version() maxima.isInstalled() if(maxima.isInstalled()) { a <- maxima.get("2+2;") iprint(a) } if(maxima.isInstalled()) { a <- maxima.get("2+2;") print(a) } if(maxima.isInstalled()) { a <- maxima.get("2+2;") maxima.eval(a) # same maxima.eval("2+2;") # evaluate with data.frame df <- data.frame(x = seq(0, 1, by = 0.1)) maxima.eval("integrate(1 / (1 + x^4), x);", code = TRUE, envir = df) maxima.stop() }
knitr
maxima engineFunctions to process Maxima code chunks by knitr
.
maxima.engine(options) maxima.inline(command)
maxima.engine(options) maxima.inline(command)
options |
named |
command |
character string containing the Maxima command to be executed. |
Upon attachment, i.e. library(rim)
function maxima.engine
is registered as a knitr
engine. Thus, maxima.engine()
is called by knit()
to evaluate Maxima code chunks. When called upon the first code chunk of a document it starts Maxima in a separate process in server mode. This means that a single Maxima session is used for all Maxima code chunks of an RMarkdown
document. Inputs and outputs can thus be used across chunks (e.g. by using Maxima reference labels). maxima.options(engine.format = ..., engine.label = ...)
configures the output format and whether or not output reference labels should be printed.
The purpose of maxima.inline
is to insert Maxima results as inline text, i.e. on the same line of the preceding text, if it is actually written on the same line of the RMarkdown
file. It uses the same running Maxima process as maxima.engine
. The output format for inline results can be configured separately from the settings of maxima.engine
, i.e. maxima.options(inline.format = ..., inline.label = ...)
.
This functions prints the resulting output from maxima together with it's cod
character string containing the maxima result printed according options set by maxima.options(inline.format = ..., inline.label = ...)
.
maxima.inline()
: This function can be used to insert maxima outputs as inline.
if (maxima.isInstalled()) { maxima.inline("2+2;") maxima.stop(engine = TRUE) }
if (maxima.isInstalled()) { maxima.inline("2+2;") maxima.stop(engine = TRUE) }
Function for globally setting and retrieving options.
maxima.options( ..., RESET = FALSE, READ.ONLY = NULL, LOCAL = FALSE, ADD = FALSE )
maxima.options( ..., RESET = FALSE, READ.ONLY = NULL, LOCAL = FALSE, ADD = FALSE )
... |
options to be accessed by using |
RESET |
logical of length 1, whether to reset all options to default values. |
READ.ONLY |
logical of length 1, can be used to output all options that are read-only. |
LOCAL |
logical of length 1, to output all options that are defined locally. |
ADD |
logical of length 1, whether to add the specified option in |
format
: character vector of length 1 setting the output format for maxima.get()
. Can be one of "linear",
"ascii",
"latex"
or "mathml"
.
engine.format
: same as option format
, but for outputs in RMarkdown
documents.
inline.format
: character string setting the output format for maxima.inline()
, for knitting outputs inline into RMarkdown
documents. Can be one of "linear"
, "latex"
or "mathml"
, but not "ascii"
.
label
: logical of length 1, whether reference labels should be printed for returned S3 objects from maxima.get()
(TRUE, default), or not (FALSE). This also applies to printing of input commands using iprint()
.
engine.label
: same as label
, but for outputs in RMarkdown
documents.
inline.label
: same as label
, but for inline outputs in RMarkdown
documents.
maxima.options(format = "latex") maxima.options(label = FALSE) maxima.options(label = TRUE, format = "ascii") # reset to default maxima.options(label = TRUE, format = "linear")
maxima.options(format = "latex") maxima.options(label = FALSE) maxima.options(label = TRUE, format = "ascii") # reset to default maxima.options(label = TRUE, format = "linear")