File: enter_m2.R

package info (click to toggle)
r-cran-m2r 1.0.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 488 kB
  • sloc: cpp: 195; python: 59; sh: 14; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,068 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
#' Enter a Macaulay2 session
#'
#' Enter a Macaulay2 session
#'
#' @param port port for Macaulay2 socket
#' @param timeout number of seconds before aborting
#' @return \code{TRUE} invisibly
#' @export
#' @examples
#'
#' \dontrun{ requires Macaulay2 be installed and an interactive session
#'
#' enter_m2()
#'
#' # m2 code below
#' 1 + 1
#' a = 1
#' a
#' R = QQ[t,x,y,z]
#' I = ideal(t^4  -  x, t^3  -  y, t^2  -  z)
#' gens gb I
#' exit
#'
#' # back in R, the variable persists using m2()
#' m2("a")
#' m2("I")
#'
#'
#' # we can also define variables in R that persist in m2
#' m2("b = 5")
#'
#' enter_m2()
#' b
#' exit
#'
#' }
#'
enter_m2 <- function (port = 27436L, timeout = 10) {
  if(!interactive()) stop("enter_m2() is only available in interactive sessions.")
  stop("enter_m2() is currently not working, check back soon!")
  suppressMessages( start_m2(port, timeout) )
  message("Entering M2 mode. Type 'exit' to go back into R.")
  repeat {
    i <- readline("i : ")
    if(i == "exit") break
    o <- m2(i)
    cat(paste0("o : ", o))
  }
  invisible(TRUE)
}