Ulteriori informazioni sul debug

La maggior parte delle operazioni viene eseguita richiamando il codice SQL che opera sui dati del database. In fase di debug, potrebbe essere interessante il codice SQL che viene chiamato. Per attivare le informazioni verbose, si può usare la funzione 'nzDebug().

L'esempio seguente verifica quali sono i tre comandi SQL SELECT utilizzati nella funzione 'nzTApply().
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)
La funzione 'nzTApply() offre un altro modo per eseguire il debug. L'uso dell'argomento 'debugger.mode consente all'utente di scaricare l'ambiente in cui si è verificato un errore. Se si verifica un errore durante l'elaborazione dei dati nel database, il set di dati corrispondente viene scaricato sul client e aperto con il comando debugger.
Nota: Per utilizzare questo metodo di debug, il pacchetto 'nzserver deve essere installato nel client R.

Mentre il nome del pacchetto deve essere disponibile nell'area di lavoro, il pacchetto installato potrebbe essere vuoto.

Per preparare uno stub nzserver vuoto, utilizzare il seguente comando:
tmp<-NULL;package.skeleton('nzrserver','tmp')
Il pacchetto può quindi essere installato. La procedura di installazione specifica dipende dal sistema operativo.
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