Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R跟踪不';在函数内部不能正常工作?_R_Trace - Fatal编程技术网

R跟踪不';在函数内部不能正常工作?

R跟踪不';在函数内部不能正常工作?,r,trace,R,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 "

跟踪
在预编译函数中似乎无法正常工作

例如,在这个片段中

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, 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))
而直接通话则可以

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
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
发生了什么,我需要什么来改变这一点

Update我禁用编译
grDevices
和其他
base
包,但是
trace
仍然无法正常工作。调试
matplot
时,
xy.coords
似乎没有跟踪


更新2这似乎与此有关,但在尝试了在命名空间中指定跟踪对象的所有建议后,仍然会调用旧对象。

对图形导入(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

xx add
where=matplot
如果您需要,可以
print=FALSE
谢谢,我没有意识到要查看导入namespace@RomanTsegelskyi请解释为什么仅仅做
trace(xy.coords,tracer=quote(cat(“test\n”)),其中=matplot)
是不够的,因为没有tracer arg,跟踪由.Primitive(“.primTrace”)执行,否则由方法::.TraceWithMethods()执行。因此有两种不同的实现。