Skip to content

Commit

Permalink
allow locals arg to as.double.latexMatrix() to be a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
john-d-fox committed Aug 16, 2024
1 parent 8e7c4ae commit 0609a76
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions R/latexMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -888,16 +888,20 @@ solve.latexMatrix <- function (a, b, simplify=FALSE,
}
}

#' @param locals an optional list of variables to be given
#' @param locals an optional list or named numeric vector of variables to be given
#' specific numeric values; e.g.,
#' \code{locals = list(a = 1, b = 5, c = -1, d = 4)}
#' \code{locals = list(a = 1, b = 5, c = -1, d = 4)} or
#' \code{locals = c(a = 1, b = 5, c = -1, d = 4)}

#' @rdname latexMatrix
#' @export
as.double.latexMatrix <- function(x, locals=list(), ...){

numericDimensions(x)

if (!is.list(locals) && is.vector(locals) && is.numeric(locals)
&& !is.null(names(locals))) locals <- as.list(locals)

X <- getBody(x)
nrow <- nrow(X)
X <- gsub("\\\\cdot", "\\*", X)
Expand Down
5 changes: 3 additions & 2 deletions man/latexMatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/latex-equations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ as.numeric(A + B)
If the elements of a matrix are valid R variable names, then it is also possible to give these elements numeric values, as in
```{r coerce-to-numeric-with-locals}
(M <- latexMatrix(matrix(letters[1:9], 3, 3)))
as.numeric(-2*M, locals=list(a=1, b=0, c=-2, d=-4, e=7, f=-1, g=0, h=4, i=6))
as.numeric(-2*M, locals=c(a=1, b=0, c=-2, d=-4, e=7, f=-1, g=0, h=4, i=6))
```


Expand Down

0 comments on commit 0609a76

Please sign in to comment.