Type: | Package |
Title: | Interface to 'Maxima', Enabling Symbolic Computation |
Version: | 0.8.1 |
Date: | 2025-07-18 |
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. |
URL: | https://rcst.github.io/rim/ |
BugReports: | https://github.com/rcst/rim/issues |
SystemRequirements: | Maxima (https://sourceforge.net/projects/maxima/, tested with versions 5.42.0 - 5.46.0), needs to be on PATH |
License: | GPL (≥ 3) |
Imports: | methods, Rcpp, R6, knitr, GlobalOptions |
LinkingTo: | Rcpp |
RoxygenNote: | 7.3.2 |
Suggests: | testthat (≥ 3.0.0), rmarkdown |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
NeedsCompilation: | yes |
Packaged: | 2025-07-18 13:24:50 UTC; eric |
Author: | Eric Stemmler [aut, cre], Kseniia Shumelchyk [aut], Hans W. Borchers [aut] |
Maintainer: | Eric Stemmler <stemmler.eric@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-18 15:20:08 UTC |
rim
Description
Provides an interface to Maxima, a computer algebra system.
Usage
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())
Arguments
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. |
Details
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)
.
Value
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
Functions
-
maxima.start()
: (re-)starts Maxima. -
maxima.stop()
: Quits Maxima. -
maxima.get()
: Executes a single Maxima command provided bycommand
. If no command ending character (;
or$
is provided,;
is appended. -
maxima.load()
: A wrapper to load a Maxima module named bymodule
-
maxima.apropos()
: A wrapper to the Maxima helper functionapropos
to lookup existing Maxima functions that matchkeystring
. -
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 bymaxima.get()
-
print(maxima)
: Prints the maxima output part of an S3 object returned bymaxima.get()
-
maxima.eval()
: Evaluates the parsed and quoted R-expression which is part of an S3 object returned bymaxima.get()
Author(s)
Maintainer: Eric Stemmler stemmler.eric@gmail.com
Authors:
Kseniia Shumelchyk shumelchyk@gmail.com
Hans W. Borchers hwborchers@googlemail.com
See Also
Useful links:
Report bugs at https://github.com/rcst/rim/issues
Examples
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("ratpow")
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 engine
Description
Functions to process Maxima code chunks by knitr
.
Usage
maxima.engine(options)
maxima.inline(command)
Arguments
options |
named |
command |
character string containing the Maxima command to be executed. |
Details
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 = ...)
.
Value
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 = ...)
.
Functions
-
maxima.inline()
: This function can be used to insert maxima outputs as inline.
Examples
if (maxima.isInstalled()) {
maxima.inline("2+2;")
maxima.stop(engine = TRUE)
}
maxima.options
Description
Function for globally setting and retrieving options.
Usage
maxima.options(
...,
RESET = FALSE,
READ.ONLY = NULL,
LOCAL = FALSE,
ADD = FALSE
)
Arguments
... |
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 |
Details
format
:character vector of length 1 setting the output format for
maxima.get()
andmaxima.repl()
. Can be one of"linear",
"ascii",
"latex"
or"mathml"
.engine.format
:same as option
format
, but for outputs inRMarkdown
documents.inline.format
:character string setting the output format for
maxima.inline()
, for knitting outputs inline intoRMarkdown
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()
andmaxima.repl()
(TRUE, default), or not (FALSE). This also applies to printing of input commands usingiprint()
.engine.label
:same as
label
, but for outputs inRMarkdown
documents.inline.label
:same as
label
, but for inline outputs inRMarkdown
documents.
Examples
maxima.options(format = "latex")
maxima.options(label = FALSE)
maxima.options(label = TRUE, format = "ascii")
# reset to default
maxima.options(label = TRUE, format = "linear")
Run a Maxima REPL
Description
This function provides a Maxima REPL in the R session, which can be used to interactively run Maxima code. All code executed within the REPL is run within the interactive Maxima session that is started when rim is attached and any generated Maxima objects will persist in the Maxima session after the REPL is detached.
Usage
maxima.repl(history_filename = NA_character_)
Arguments
history_filename |
A (optional) filename to which all Maxima commands during the repl session are saved. If not provided (default), command history lookup will still be available (if supported by OS) in the same way as in the R session. |
Details
When working with R and Maxima scripts interactively, one can activate the Python REPL with 'maxima.repl()', run Maxima code, and later run 'exit;' to return to the R console.
Note that, inside the REPL, multiple commands are allowed.
The output format displayed inside the REPL is controlled by 'maxima.options(repl.format = ...)'.
rim_global
Description
Returns knitr::knit_global() unless this returs the GlobalEnv() in which case it returns maxima.env, rim's internal environment. Main purpose is to prevent 'knitr::knit_global()' from returning 'globalenv()'.
Usage
rim_global()
Value
An environment, either the result of knitr::knit_global or maxima.env