knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = FALSE
)

caracas: Computer algebra in R

R build status codecov

Installation

caracas is available on CRAN and can be installed as usual:

install.packages('caracas')

Two more steps must be completed before caracas can be used:

Installing python

caracas uses python (and in particular the python library SymPy). Therefore python (version > 3) must be installed, which can be done as follows: Go here and download the version for your computer.

For windows users: During installation you can check "add python to the computers path" or similar. It is important that you check this box.

Installing SymPy

Please ensure that you have SymPy installed, or else install it:

if (!caracas::has_sympy()) {
  caracas::install_sympy() 
}

Using development versions of caracas

To build and install from Github with vignettes run this command from within R (please install remotes first if not already installed):

# install.packages('remotes')
remotes::install_github("r-cas/caracas", build_vignettes = TRUE)

You can also install the package without vignettes if needed as follows:

remotes::install_github("r-cas/caracas")

Configuring the Python environment

The caracas package uses the reticulate package (to run Python code). Thus, if you wish to configure your Python environment, you need to 1) load reticulate, 2) configure the Python environment, and 3) load caracas. The Python environment can be configured as described here. Again, this need to be done before loading caracas.

For linux users, specifically, do:

library(reticulate)
reticulate::import("sympy")
reticulate::py_install(packages="sympy")
reticulate::import("sympy") 

If the prompt says Module(sympy) things should be fine.

Development site

See https://github.com/r-cas/caracas.

Online documentation

See https://r-cas.github.io/caracas/.

Reference card

Reference card available at https://raw.githubusercontent.com/r-cas/caracas/master/refcard/caracas_refcard.pdf.

Reference card

Origin of name

The name "caracas" is intended to mean "(inter)face to computer algebra system(s)" - notice that "cara" is Spanish (Castellano to be precise) for "face".

Code of conduct

Please note that the caracas project is released with a Contributor Code of Conduct (available in CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.

Brief introduction

library(caracas)
# options(caracas.print.prettyascii = TRUE)
if (!has_sympy()) {
  # SymPy not available, so the chunks shall not be evaluated
  knitr::opts_chunk$set(eval = FALSE)
}
x <- symbol('x')
eq <- 2*x^2 - x
eq
as.character(eq)
as_expr(eq)
tex(eq)
solve_sys(eq, x)
der(eq, x)
subs(eq, x, "y")
A <- matrix(c("x", 2, 0, "2*x"), 2, 2)
B <- as_sym(A)
B
Binv <- inv(B)
Binv
tex(Binv)
eigenval(Binv)

Please find more examples in the other vignettes available at https://r-cas.github.io/caracas/.

Contribute, issues, and support

Please use the issue tracker at https://github.com/r-cas/caracas/issues if you want to notify us of an issue or need support. If you want to contribute, please either create an issue or make a pull request.



r-cas/caracas documentation built on Feb. 28, 2025, 3:39 p.m.