# 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(" x * y")
# Explicitly assign x, while inheriting y.
owl(" x * y", x = 2)
# An alternative arrangement of arguments.
owl(x = 3, query = " x * y", y = 1)
# Write the script to file.
myfile <- tempfile()
writeLines(" 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(" x * y ",
" x + y "),
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