Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate into lists #19

Closed
mpadge opened this issue Jun 22, 2023 · 2 comments
Closed

Iterate into lists #19

mpadge opened this issue Jun 22, 2023 · 2 comments

Comments

@mpadge
Copy link
Owner

mpadge commented Jun 22, 2023

The current R Consortium funding was granted with the caveat that:

The ISC... has questions on the applicability when it comes to complex, nested types.

All the work actually proposed has now been addressed via #14, but that suggests that future applications will require also addressing "complex, nested types" in the final report for this phase. This will require an additional parameter, trace_lists = FALSE which, when TRUE, will iterate into all list items, including data.frame-type objects, and tracing the types of all components of those.

mpadge added a commit that referenced this issue Jun 23, 2023
mpadge added a commit that referenced this issue Jun 23, 2023
@mpadge
Copy link
Owner Author

mpadge commented Jun 23, 2023

Those commits implement most of it, but still

TODO

  • Expose parameter in non-package workflow
  • Test non-default trace_lists = TRUE
  • Add vignette on recursion into lists

Added demo in README which seems enough for now.

mpadge added a commit that referenced this issue Jun 23, 2023
mpadge added a commit that referenced this issue Jun 23, 2023
@mpadge mpadge closed this as completed in b47da84 Jun 23, 2023
mpadge added a commit that referenced this issue Jun 23, 2023
read embedded list data on load_traces for #19
@mpadge
Copy link
Owner Author

mpadge commented Jun 23, 2023

Here's a reprex in action on direct function injection from the README:

library (typetracer)
f <- function (x, y, z, ...) {
    x * x + y * y
}
inject_tracer (f, trace_lists = FALSE)
val <- f (
    x = 1:2,
    y = 3:4 + 0.,
    a = "blah",
    b = list (a = 1, b = "b"),
    f = a ~ b
)
x0 <- load_traces ()
x0 [, 1:4]
#> # A tibble: 7 × 4
#>   trace_number fn_name fn_call_hash par_name
#>          <int> <chr>   <chr>        <chr>   
#> 1            0 f       BaewofTV     x       
#> 2            0 f       BaewofTV     y       
#> 3            0 f       BaewofTV     z       
#> 4            0 f       BaewofTV     ...     
#> 5            0 f       BaewofTV     a       
#> 6            0 f       BaewofTV     b       
#> 7            0 f       BaewofTV     f

uninject_tracer (f)
#> [1] TRUE
clear_traces ()
inject_tracer (f, trace_lists = TRUE)
val <- f (
    x = 1:2,
    y = 3:4 + 0.,
    a = "blah",
    b = list (a = 1, b = "b"),
    f = a ~ b
)
x1 <- load_traces ()
x1 [, 1:4]
#> # A tibble: 9 × 4
#>   trace_number fn_name fn_call_hash par_name
#>          <int> <chr>   <chr>        <chr>   
#> 1            0 f       wIPQLobz     x       
#> 2            0 f       wIPQLobz     y       
#> 3            0 f       wIPQLobz     z       
#> 4            0 f       wIPQLobz     ...     
#> 5            0 f       wIPQLobz     a       
#> 6            0 f       wIPQLobz     b       
#> 7            0 f       wIPQLobz     f       
#> 8            0 f       wIPQLobz     b$a     
#> 9            0 f       wIPQLobz     b$b

Created on 2023-06-23 with reprex v2.0.2

And here is a full package example, from geodist which includes on example of submitting a data.frame:

library (typetracer)
x0 <- trace_package ("geodist", trace_lists = FALSE)
nrow (x0); length (grep ("\\$", x0$par_name))
#> [1] 217
#> [1] 0

x1 <- trace_package ("geodist", trace_lists = TRUE)
nrow (x1); length (grep ("\\$", x1$par_name))
#> [1] 219
#> [1] 2

x1 [grep ("\\$", x1$par_name), ]
#> # A tibble: 2 × 14
#>   trace_number source_file_name fn_name fn_call_hash call_env     par_name class
#>          <int> <chr>            <chr>   <chr>        <chr>        <chr>    <I<l>
#> 1            5 man/geodist.Rd   geodist DCohEJdm     typetracer:… x$x      <chr>
#> 2            5 man/geodist.Rd   geodist DCohEJdm     typetracer:… x$y      <chr>
#> # ℹ 7 more variables: typeof <chr>, mode <chr>, storage_mode <chr>,
#> #   length <int>, formal <named list>, uneval <I<list>>, eval <I<list>>

Created on 2023-06-23 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant