# NOT RUN {
# Some default values, for demonstration purposes.
x <- 1; y <- 2
# Define a new SQRL source and its interface. The DSN need
# not exist, but this will fail (by design) if a function
# called 'owl' already exists on the R search path.
sqrlSource("owl", dsn = "HundredAcreWood")
# This (ordinarily pointless) SQRL script contains no SQL,
# which allows it to run even when the DSN does not exist
# (there being no need to open a connection). In this case,
# the x and y variables are implicitly inherited.
owl("<R> x * y")
# Explicitly assign x, while inheriting y.
owl("<R> x * y", x = 2)
# Write the script to file.
myfile <- tempfile()
writeLines("<R> x * y", myfile)
# Run the script from file, inheriting variables.
owl(myfile)
# Run the script from file, with explicit arguments.
# (These are all equivalent.)
owl(myfile, x = 2, y = 3)
owl(myfile, list(x = 2, y = 3))
owl(myfile, args = list(x = 2, y = 3))
owl(file = myfile, x = 2, y = 3)
owl(file = myfile, list(x = 2, y = 3))
owl(file = myfile, args = list(x = 2, y = 3))
owl(list(file = myfile, x = 2, y = 3))
owl(list(file = myfile, args = list(x = 2, y = 3)))
# With the file path specified as components.
owl(dirname(myfile), "/", basename(myfile), x = 2, y = 3)
owl(file = c(dirname(myfile), "/", basename(myfile)),
args = list(x = 2, y = 3))
# Construct a library file (of procedure definitions).
mylibraryfile <- tempfile()
writeLines(c("<proc 'proc-a'> <R> x * y </proc>",
"<proc 'proc-b'> <R> x + y </proc>"),
mylibraryfile)
# Import procedures from file (to owl's library).
owl(library = mylibraryfile)
# Run the imported procedures.
owl("proc-a")
owl("proc-b", x = 2, y = c(3, 4))
# Review the last result.
owl("result")
# Clean-up.
unlink(c(myfile, mylibraryfile))
owl("remove")
# }
Run the code above in your browser using DataLab