# NOT RUN {
# See file .../library/PBSmodelling/testWidgets/LissWin.txt
# Calculate and draw the Lissajous figure
local(envir=.PBSmodEnv,expr={
drawLiss <- function() {
oldpar = par(no.readonly=TRUE); on.exit(par(oldpar))
getWinVal(scope="L"); ti=2*pi*(0:k)/k;
x=sin(2*pi*m*ti); y=sin(2*pi*(n*ti+phi));
plot(x,y,type=ptype); invisible(NULL); };
createWin(system.file("testWidgets/LissWin.txt",package="PBSmodelling"));
})
############################################################
# Environment example:
# function in global
local(envir=.PBSmodEnv,expr={
hello <- function() {
stop( "I shouldn't be called" )
}
newNameGreeter <- function( name ) {
# method to display window
greet <- function() {
createWin(c("button \"Say hello\" func=hello"), astext=TRUE,
env=parent.env(environment()))
}
# hello method will refer to the name in this local scope
hello <- function() {
cat( "Hello", name, "\n" )
}
# return functions which the user can call directly
return( list( greet=greet, hello=hello ) )
}
alex <- newNameGreeter( "Alex" )
jon <- newNameGreeter( "Jon" )
alex$hello() # prints hello Alex
jon$hello() # prints hello Jon
alex$greet() # creates a GUI with a button, which will print "hello Alex" when pushed
})
# }
Run the code above in your browser using DataLab