Skip to content

Commit 0951b70

Browse files
committed
Support traced functions in View()
1 parent a19a302 commit 0951b70

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

crates/ark/src/modules/positron/view.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ view_function_info <- function(
9898
) {
9999
stopifnot(is.function(x))
100100

101+
# Extract original function if `x` has been `trace()`d
102+
if (inherits(x, "functionWithTrace") && is.function(x@original)) {
103+
x <- x@original
104+
}
105+
101106
# Only resource the namespace if we're at top-level. Doing it while
102107
# arbitrary code is running is unsafe as the source references are mutated
103108
# globally. The mutation could invalidate assumptions made by running code.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: crates/ark/src/view.rs
3+
expression: doc
4+
---
5+
URI: ark:ark-*pid*/global/foo.R
6+
7+
function (arg)
8+
body

crates/ark/src/view.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,18 @@ mod tests {
100100
)
101101
});
102102
}
103+
104+
#[test]
105+
fn test_view_function_trace() {
106+
crate::r_task(|| {
107+
eval_and_snapshot!(
108+
"
109+
{
110+
foo <- function(arg) body
111+
trace(foo, identity)
112+
.ps.internal(view_function_test(foo, 'foo', globalenv()))
113+
}"
114+
)
115+
});
116+
}
103117
}

0 commit comments

Comments
 (0)