R Under development (unstable) (2024-01-28 r85838 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("R.rsp") R.rsp v0.46.0 successfully loaded. See ?R.rsp for help. > > rcat("A random integer in [1,100]: <%=sample(1:100, size=1)%>\n") A random integer in [1,100]: 65 > > # Passing arguments > rcat("A random integer in [1,<%=K%>]: <%=sample(1:K, size=1)%>\n", args=list(K=50)) A random integer in [1,50]: 7 > > text <- 'The <%=n <- length(letters)%> letters in the English alphabet are: + <% for (i in 1:n) { %> + <%=letters[i]%>/<%=LETTERS[i]%><%=if(i < n) ", "-%> + <% } %>.\n' > rcat(text) The 26 letters in the English alphabet are: a/A, b/B, c/C, d/D, e/E, f/F, g/G, h/H, i/I, j/J, k/K, l/L, m/M, n/N, o/O, p/P, q/Q, r/R, s/S, t/T, u/U, v/V, w/W, x/X, y/Y, z/Z. > > > # Informative syntax error messages > text <- '<%={ + 10 print "Hello world!" + 20 goto 10 + }%>\n' > tryCatch({ rcat(text) }, error=function(ex) cat(ex$message)) RSP code chunk (#1): <%= { 10 print "Hello world!" 20 goto 10 } %> does not contain a complete or valid R expression: Error in base::parse(text = codeT): :2:4: unexpected symbol 1: ({{ 2: 10 print ^ > > > rcat("A random integer in [1,100]: <%=sample(1:100, size=1)%>\n", verbose = TRUE) rcat() for default... Length of RSP string: 56 rcat() for RspString... Buffered: TRUE Type of output: RspStringProduct Arguments: chr "*" Result: 'RspStringProduct' chr "A random integer in [1,100]: 18\n" - attr(*, "verbose")= - attr(*, "type")= chr NA - attr(*, "metadata")= list() Outputting... Output: Appending: FALSE String: (nchars = 32) 'A random integer in [1,100]: 18 ' A random integer in [1,100]: 18 Outputting...done rcat() for RspString...done rcat() for default...done > > > proc.time() user system elapsed 0.73 0.15 0.85