Skip to content

[Query] Dependencies

github-actions[bot] edited this page Jul 21, 2026 · 1 revision

This document was generated from 'src/documentation/wiki-query.ts' on 2026-07-21, 13:36:09 UTC presenting an overview of flowR's query API (v2.13.1). Please do not edit this file/wiki page directly.

Dependencies Query [overview]

Returns all direct dependencies (in- and outputs) of a given R script
This query is requested with the type dependencies.

This query extracts all dependencies from an R script, using a combination of a Call-Context Query and more advanced tracking in the Dataflow Graph. Loaded libraries are resolved against the signature database.

In other words, if you have a script simply reading: library(x), the following query returns the loaded library:

[ { "type": "dependencies" } ]

(This can be shortened to @dependencies when used with the REPL command :query).

Results (prettified and summarized):

Query: dependencies (2 ms)
   Libraries (1)
     x via library (node 3)
All queries together required ≈8 ms (1ms accuracy, total 9 ms)

Show Detailed Results as Json

The analysis required 8.7 ms (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "dependencies": {
    ".meta": {
      "timing": 2
    },
    "library": [
      {
        "nodeId": 3,
        "functionName": "library",
        "value": "x"
      }
    ],
    "source": [],
    "read": [],
    "write": [],
    "visualize": [],
    "test": []
  },
  ".meta": {
    "timing": 8
  }
}

Of course, this works for more complicated scripts too. The query offers information on the loaded libraries, sourced files, data which is read and data which is written. For example, consider the following script:

source("sample.R")
foo <- loadNamespace("bar")

data <- read.csv("data.csv")

#' @importFrom ggplot2 ggplot geom_point aes
ggplot(data, aes(x=x, y=y)) + geom_point()

better::write.csv(data, "data2.csv")
print("hello world!")

The following query returns the dependencies of the script.

[ { "type": "dependencies" } ]

(This can be shortened to @dependencies when used with the REPL command :query).

Show Results

Results (prettified and summarized):

Query: dependencies (3 ms)
   Libraries (2)
     bar via loadNamespace (node 8)
     better via :: (node 32)
   Sourced Files (1)
     sample.R via source (node 3)
   Read Data (1)
     data.csv via read.csv (node 14)
   Written Data (1)
     stdout via print (node 41)
   Visualizations (2)
      via ggplot (node 28)
      via geom_point (node 30, linked 28)
All queries together required ≈14 ms (1ms accuracy, total 14 ms)

Show Detailed Results as Json

The analysis required 14.2 ms (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "dependencies": {
    ".meta": {
      "timing": 3
    },
    "library": [
      {
        "nodeId": 8,
        "functionName": "loadNamespace",
        "value": "bar"
      },
      {
        "nodeId": 32,
        "functionName": "::",
        "value": "better"
      }
    ],
    "source": [
      {
        "nodeId": 3,
        "functionName": "source",
        "value": "sample.R"
      }
    ],
    "read": [
      {
        "nodeId": 14,
        "functionName": "read.csv",
        "value": "data.csv"
      }
    ],
    "write": [
      {
        "nodeId": 41,
        "functionName": "print",
        "value": "stdout"
      }
    ],
    "visualize": [
      {
        "nodeId": 28,
        "functionName": "ggplot"
      },
      {
        "nodeId": 30,
        "functionName": "geom_point",
        "linkedIds": [
          28
        ]
      }
    ],
    "test": []
  },
  ".meta": {
    "timing": 14
  }
}

Currently, the dependency extraction may fail as it is essentially a set of heuristics guessing the dependencies. We welcome any feedback on this (consider opening a new issue).

In the meantime we offer several properties to overwrite the default behavior (e.g., function names that should be collected)

[
  {
    "type": "dependencies",
    "ignoreDefaultFunctions": true,
    "enabledCategories": [
      "library"
    ],
    "libraryFunctions": [
      {
        "package": "base",
        "name": "print",
        "argIdx": 0,
        "argName": "library",
        "resolveValue": true
      }
    ]
  }
]
Show Results

Results (prettified and summarized):

Query: dependencies (0 ms)
   Libraries (1)
     hello world! via print (node 41)
All queries together required ≈12 ms (1ms accuracy, total 13 ms)

Show Detailed Results as Json

The analysis required 12.8 ms (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "dependencies": {
    ".meta": {
      "timing": 0
    },
    "library": [
      {
        "nodeId": 41,
        "functionName": "print",
        "value": "hello world!"
      }
    ],
    "source": [],
    "read": [],
    "write": [],
    "visualize": [],
    "test": []
  },
  ".meta": {
    "timing": 12
  }
}

Here, resolveValue tells the dependency query to resolve the value of this argument in case it is not a constant.

Implementation Details

Responsible for the execution of the Dependencies Query query is executeDependenciesQuery in ./src/queries/catalog/dependencies-query/dependencies-query-executor.ts.

Clone this wiki locally