File: use_ring.R

package info (click to toggle)
r-cran-m2r 1.0.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 472 kB
  • sloc: cpp: 195; python: 59; sh: 14; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#' Set Macaulay2 ring
#'
#' \code{use_ring()} sets the default referent ring on the Macaulay2
#' side using the \code{use} function.
#'
#' @param ring a \code{m2_ring} (see [ring()]),
#'   \code{m2_ring_pointer} (see [ring.()]), or a character
#'   string containing the name of a ring in Macaulay2
#' @name use_ring
#' @examples
#'
#' \dontrun{ requires Macaulay2
#'
#'
#' ##### basic usage
#' ########################################
#'
#' ring("x", coefring = "QQ")
#' factor_poly("x^4 + 1")
#'
#' QQtxyz <- ring("t","x","y","z", coefring = "QQ")
#' gb("t^4 - x", "t^3 - y", "t^2 - z")
#'
#' ring("x", "y", "z", "t", coefring = "QQ")
#' gb("t^4 - x", "t^3 - y", "t^2 - z")
#'
#' use_ring(QQtxyz)
#' gb("t^4 - x", "t^3 - y", "t^2 - z")
#'
#' }




#' @export
#' @rdname use_ring
use_ring <- function(ring) {

  # arg check
  stopifnot(is.m2_polynomialring(ring) || is.m2_polynomialring_pointer(ring) || is.character(ring))

  # construct code
  if (is.m2(ring)) {
    m2_code <- sprintf("use %s", m2_name(ring))
  } else {
    m2_code <- sprintf("use %s", ring)
  }

  # run m2
  out <- m2.(m2_code)

  # return
  invisible(out)

}