【发布时间】:2016-01-06 10:00:35
【问题描述】:
trace 在预编译函数中似乎无法正常工作
比如在这个sn-p中
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))
xy.coords 的简单 trace 工作正常
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 有关,但在尝试了那里建议的一切并在命名空间中分配跟踪对象后,旧的仍然被调用。
【问题讨论】:
-
如果需要,可以添加
where = matplot和print = FALSE