title: rmarkdown render NSE function fails only inside callr
body: <p>I seem to have a weird combination of NSE, rmarkdown and callr, similar in flavor to <a href="https://stackoverflow.com/questions/59341040/is-it-possible-to-disable-callr-for-rmarkdown">Is it possible to disable `callr` for RMarkdown?</a>.</p>
  <p>When I set a value to a variable to use it in something similar to a filter call implemented using NSE via nested evals and list calls, it fails horribly, but only in callr.</p>
  <pre><code>---
  title: &quot;Test CC2 Failure Reproducibly&quot;
  author: &quot;Robert M Flight&quot;
  output: rmarkdown::md_document
  editor_options: 
    chunk_output_type: console
  ---
  
  
  ```{r run_enrichments}
  set.seed(1234)
  create_go_annotation = function(db, ontology = NULL){
    all_genes = keys(db)
    go_all_gene = AnnotationDbi::select(db, keys = all_genes, columns = c(&quot;GOALL&quot;, &quot;ONTOLOGYALL&quot;))
    
    if (!is.null(ontology)) {
      go_all_gene = go_all_gene[go_all_gene$ONTOLOGYALL == ontology, ]
      ontology_type = paste0(&quot;GO.&quot;, ontology)
    } else {
      ontology_type = &quot;GO.all&quot;
    }
    go_2_gene = split(go_all_gene$ENTREZID, go_all_gene$GOALL)
    go_2_gene = lapply(go_2_gene, unique)
    go_desc = AnnotationDbi::select(GO.db::GO.db, keys = names(go_2_gene), columns = &quot;TERM&quot;, keytype = &quot;GOID&quot;)$TERM
    names(go_desc) = names(go_2_gene)
  
    go_annotation = categoryCompare2::annotation(annotation_features = go_2_gene,
                                                 description = go_desc,
                                                 annotation_type = ontology_type,
                                                 feature_type = &quot;ENTREZID&quot;)
    go_annotation
  }
  
  
  library(org.Hs.eg.db)
  library(GO.db)
  library(categoryCompare2)
  library(methods)
  
  go_mf = create_go_annotation(org.Hs.eg.db, &quot;MF&quot;)
  
  all_features = unique(unlist(go_mf@annotation_features))
  sig_features = sample(all_features, 500)
  
  enrich = hypergeometric_feature_enrichment(
    new(&quot;hypergeom_features&quot;, significant = sig_features,
        universe = all_features,
        annotation = go_mf),
    p_adjust = &quot;BH&quot;
  )
  
  comb_enrich = combine_enrichments(sig1 = enrich)
  sig_cutoff = 0.1
  filter_enrich = get_significant_annotations(comb_enrich, padjust &lt;= sig_cutoff)
  ```
  </code></pre>
  <p>Run it via callr:</p>
  <pre><code>r(function() rmarkdown::render(here::here(&quot;categoryCompare2_failure.Rmd&quot;), output_file = &quot;cc2_fails_1.md&quot;), show = TRUE)
  
  # Quitting from lines 13-57 (categoryCompare2_failure.Rmd)
  # 
  # Error in FUN(X[[i]], ...) : object 'sig_cutoff' not found
  # Error: callr subprocess failed: object 'sig_cutoff' not found
  
  # &gt; .Last.error.trace
  # Stack trace:
  #   Process 221313:
  #   1. callr:::r(function() rmarkdown::render(here::he ...
  #     2. callr:::get_result(output = out, options)
  #     3. throw(newerr, parent = remerr[[2]])
  #         x callr subprocess failed: object 'sig_cutoff' not found
  #   Process 221619:
  #   15. (function () ...
  #   16. rmarkdown::render(here::here(&quot;categoryCompare2_failure.Rmd&quot;))
  #   17. knitr::knit(knit_input, knit_output, envir = envir, quiet ...
  #   18. knitr:::process_file(text, output)
  #   19. base:::withCallingHandlers(if (tangle) process_tangle(gro ...
  #   20. knitr:::process_group(group)
  #   21. knitr:::process_group.block(group)
  #   22. knitr:::call_block(x)
  #   23. knitr:::block_exec(params)
  #   24. knitr:::eng_r(options)
  #   25. knitr:::in_dir(input_dir(), evaluate(code, envir = env, n ...
  #   26. knitr:::evaluate(code, envir = env, new_device = FALSE, k ...
  #   27. evaluate::evaluate(...)
  #   28. evaluate:::evaluate_call(expr, parsed$src[[i]], envir = e ...
  #   29. evaluate:::timing_fn(handle(ev &lt;- withCallingHandlers(wit ...
  #   30. base:::handle(ev &lt;- withCallingHandlers(withVisible(eval( ...
  #   31. base:::withCallingHandlers(withVisible(eval(expr, envir, ...
  #   32. base:::withVisible(eval(expr, envir, enclos))
  #   33. base:::eval(expr, envir, enclos)
  #   34. base:::eval(expr, envir, enclos)
  #   35. categoryCompare2:::get_significant_annotations(comb_enric ...
  #   36. categoryCompare2:::get_significant_annotations(comb_enric ...
  #   37. categoryCompare2:::.get_significant_combined_enrichment(i ...
  #   38. base:::lapply(in_results@enriched, function(x) { ...
  #   39. categoryCompare2:::FUN(X[[i]], ...)
  #   40. categoryCompare2:::get_significant_annotations(x@statisti ...
  #   41. categoryCompare2:::get_significant_annotations(x@statisti ...
  #   42. categoryCompare2:::.get_significant_stat_results(in_resul ...
  #   43. categoryCompare2:::multi_query_list(in_results@statistic_ ...
  #   44. base:::lapply(queries, eval, list_to_query)
  #   45. base:::FUN(X[[i]], ...)
  #   46. base:::FUN(X[[i]], ...)
  #   47. base:::.handleSimpleError(function (e) ...
  #   48. h(simpleError(msg, call))
  #     x object 'sig_cutoff' not found
  </code></pre>
  <p>You can see that it complains that <code>sig_cutoff</code> is not found, but it exists in the environment, but does not seem to get passed down.</p>
  <p>If I instead run it directly, it works:</p>
  <pre><code>rmarkdown::render(here::here(&quot;categoryCompare2_failure.Rmd&quot;), output_file = &quot;cc2_works.md&quot;)
  </code></pre>
  <p>I've put all the code in a <a href="https://github.com/rmflight/cc2_nse_rmarkdown_bug" rel="nofollow noreferrer">github repo</a>.</p>
  <p>Interestingly, it's definitely a callr issue, because targets has the same issue.</p>
  <p>callr v 1.0.7, rmarkdown v 2.11, R 4.1.0</p>
  <p>Other package versions are in the <a href="https://github.com/rmflight/cc2_nse_rmarkdown_bug/blob/main/renv.lock" rel="nofollow noreferrer">renv.lock</a> file.</p>