To temporarily edit the body of a packaged function func
, I frequently use trace(func, edit=TRUE)
. For some reason, though, R isn't letting me do this when func
is [.data.table
:
## Note: In this and the other cases below, once an editor pops up, I save and
## and then exit without making any edits to the function. The commented-out
## message below each call to trace() is what is then printed to my R console.
trace("[.data.table", where=data.table, edit=TRUE)
# Error in .makeTracedFunction(def, tracer, exit, at, print, doEdit) :
# the editing in trace() can only change the body of the function, not
# the arguments or defaults
Questions: What might be causing this error? What other functions also trigger it? For such functions, is there some alternative work-around that will allow me to edit them?
FWIW, this doesn't seem to be some general issue with functions in data.table's namespace (see e.g. #1
below) nor is it an issue with subset methods in general (see e.g. #2
below).
## (#1)
trace("within.data.table", where=data.table, edit=TRUE)
# Tracing function "within.data.table" as seen from package "data.table"
# [1] "within.data.table"
## (#2)
trace("[.Date", edit=TRUE)
# Tracing function "[.Date" in package "base"
# [1] "[.Date"
I am running R-3.0.0
and data.table_1.8.8
on a Windows XP machine, and get the same error whether I use set options(editor="emacs")
, options(editor="notepad")
or use the R GUI's default editor.
This is apparently being caused by the recent addition of curly braces (i.e.
{}
) at one place indata.table
's formal argument list.First, a MRE to show that braces really do cause
trace(..., edit=TRUE)
to choke:Then, for the record, here are the formals for
[.data.table
in versions 1.8.6 (for which tracing works) and version 1.8.8 (for which it doesn't):