More on debugging

Most operations are done by calling SQL code that operates on data in the database. When debugging, the SQL code that is being called might be of interest. To turn on verbose information, you can use the nzDebug() function.

The following example checks which three SQL SELECT commands are used in the nzTApply() function.
nzDebug(TRUE)
nzTApply(nzIris, "CLASS", function(x) mean(x))
#SELECT filename FROM TABLE WITH
#FINAL(nzr..placefile('base64text','QQoyCjEzMzM3N...
#SELECT UPPER(attname) AS field FROM _V_RELATION_COLUMN
# WHERE UPPER(name) = UPPER('IRIS')
#SELECT ae_output_t.* FROM (SELECT row_number() OVER(PARTITION BY CLASS ORDER #BY
CLASS) AS nzrn, count(*) OVER (PARTITION BY CLASS) AS nzcnt, from_alias.* #FROM
(SELECT ID,SEPALLENGTH,SEPALWIDTH,PETALLENGTH,PETALWIDTH,CLASS FROM IRIS) #AS
from_alias) AS outer_from, TABLE WITH FINAL
#(nzr..r_udtf(ID,SEPALLENGTH,SEPALWIDTH,PETALLENGTH,PETALWIDTH,CLASS,CLASS,
#nzrn, nzcnt, 'WORKSPACE_PATH=file579be4f1')) AS ae_output_t
# ID SEPALLENGTH SEPALWIDTH PETALLENGTH PETALWIDTH CLASS CLASS
#1 125.5 6.588 2.974 5.552 2.026 nan virginica
#2 25.5 5.006 3.418 1.464 0.244 nan setosa
#3 75.5 5.936 2.770 4.260 1.326 nan versicolor
nzDebug(FALSE)
The nzTApply() function provides another way of debugging. Using the debugger.mode argument allows the user to download the environment where an error occurred. If an error occurs during data processing in the database, the corresponding data set is downloaded to the client and opened with the debugger command.
Note: To use this method of debugging, the nzserver package must be installed in the R client.

While the package name must be available in the workspace, the installed package might be empty.

To prepare an empty nzserver stub, use the following command:
tmp<-NULL;package.skeleton('nzrserver','tmp')
The package can then be installed. The specific installation procedure depends on the operating system.
FUN2debug = function(x) if(min(x[,1]) < 4.5) cov(0) else min(x[,1])
nzTApply(nzIris, "CLASS", FUN2debug, debugger.mode=T)
# Found 1 error
# values type group
#1 101 integer virginica
#2 supply both 'x' and 'y' or a matrix-like 'x' try-error setosa
#3 51 integer versicolor
#
#
# Recalling environment for group setosa
# Take environment no. 11 and check for the args variable
# Message: supply both 'x' and 'y' or a matrix-like 'x'Available environments
#had calls:
#1: dispatcher()
#2: try(handleConnection(), silent = TRUE)
#3: tryCatch(expr, error = function(e) {
#4: tryCatchList(expr, classes, parentenv, handlers)
#5: tryCatchOne(expr, names, parentenv, handlers[[1]])
#6: doTryCatch(return(expr), name, parentenv, handler)
#7: handleConnection()
#8: runWrapper()
#9: nzrsrv.tapply(userData$fun, userData$args, userData$cols)
#10: process.cell(data)
#11: do.call(fun, c(list(x = data), args))
#12: function (..., FUN2s)
#13: tryCatch(FUN2s(...), error = function(e) {
#14: tryCatchList(expr, classes, parentenv, handlers)
#15: tryCatchOne(expr, names, parentenv, handlers[[1]])

#Enter an environment number, or 0 to exit Selection: 11
#Browsing in the environment with call:
# do.call(fun, c(list(x = data), args))
#Called from: debugger.look(ind)
#Browse[1]> args
#$x
# id sepallength sepalwidth petallength petalwidth class
#1 4 4.6 3.1 1.5 0.2 setosa
#2 31 4.8 3.1 1.6 0.2 setosa
#3 27 5.0 3.4 1.6 0.4 setosa
#4 23 4.6 3.6 1.0 0.2 setosa