trace
在预编译函数中似乎无法正常工作
例如,在这个片段中
xx <- 2:7
nu <- seq(-10, 9, length.out = 2001)
op <- par(lab = c(16, 5, 7))
matplot(nu, t(outer(xx, nu, besselI)), type = "l", ylim = c(-50, 200),
main = expression(paste("Bessel ", I[nu](x), " for fixed ", x,
", as ", f(nu))),
xlab = expression(nu))
简单
trace
为 xy.coords
工作正常trace(xy.coords)
matplot(nu, t(outer(xx, nu, besselI)), type = "l", ylim = c(-50, 200),
main = expression(paste("Bessel ", I[nu](x), " for fixed ", x,
", as ", f(nu))),
xlab = expression(nu))
# trace: xy.coords
# trace: xy.coords
# trace: xy.coords
# trace: xy.coords
# trace: xy.coords
# trace: xy.coords
# trace: xy.coords
但是用函数跟踪似乎不起作用
trace(xy.coords, tracer = quote(cat("test\n")))
# Tracing function "xy.coords" in package "grDevices"
# [1] "xy.coords"
matplot(nu, t(outer(xx, nu, besselI)), type = "l", ylim = c(-50, 200),
main = expression(paste("Bessel ", I[nu](x), " for fixed ", x,
", as ", f(nu))),
xlab = expression(nu))
虽然直接调用工作正常
xy.coords(1:3, 1:2, recycle = TRUE)
# Tracing xy.coords(1:3, 1:2, recycle = TRUE) on entry
# test
# $x
# [1] 1 2 3
#
# $y
# [1] 1 2 1
#
# $xlab
# NULL
#
# $ylab
# NULL
发生了什么,我需要做什么来改变它?
更新 我禁用了
grDevices
的编译和其他 base
包,但 trace
仍然不能正常工作。调试时matplot
, xy.coords
似乎无迹可寻。更新 2 这似乎与Override a function that is imported in a namespace有关,但是在尝试了所有建议并在命名空间中分配跟踪对象后,旧的仍然被调用。
最佳答案
对图形的导入(matplot 所属的地方)采取行动似乎可以解决问题:
xx <- 2:7
nu <- seq(-10, 9, length.out = 2001)
op <- par(lab = c(16, 5, 7))
trace(xy.coords, tracer = quote(cat("test\n")))
# get the imports env of graphics
nsi <- parent.env(getNamespace('graphics'))
unlockBinding("xy.coords", nsi)
assign('xy.coords', xy.coords, nsi)
matplot(nu, t(outer(xx, nu, besselI)), type = "l", ylim = c(-50, 200),
main = expression(paste("Bessel ", I[nu](x), " for fixed ", x,
", as ", f(nu))),
xlab = expression(nu))
Tracing xy.coords(x, y, xlabel, ylabel, log = log) on entry
test
Tracing xy.coords(x, y, xlabel, ylabel, log) on entry
test
Tracing xy.coords(x, y) on entry
test
Tracing xy.coords(x, y) on entry
test
Tracing xy.coords(x, y) on entry
test
Tracing xy.coords(x, y) on entry
test
Tracing xy.coords(x, y) on entry
test
关于R 跟踪在函数内部无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33021574/