Skip to contents

Creates an independent server in the current R runtime. This entry point is suitable for dedicated webR workers and other hosts without subprocesses. Send complete, unframed LSP JSON-RPC messages in arrival order. The host forwards each returned string to its language client. On disposal, send shutdown and exit, or release the function and its worker.

Usage

run_embedded(package_context = NULL)

Arguments

package_context

Optional function returning the package context of a separate R execution session. Return a list with character vectors installed (visible package names) and attached (first-to-last search order), or NULL to use this R interpreter's own library. The host makes compatible package files available on .libPaths() before sending a request. attached includes packages whose metadata is unavailable. The optional character vector unavailable identifies installed packages whose namespaces the analysis runtime cannot inspect. Their names can still complete. An unqualified name may resolve to a later package when an earlier package cannot be inspected. Change the optional revision to invalidate the server's package caches when package names and attachment order stay the same. R retains loaded namespaces and DLLs. When replacing or removing a package already loaded in the analysis runtime, the host must start a fresh R runtime (a new worker in webR), create a new dispatcher, and replay initialization and open documents.

Value

A function taking a single JSON string and returning a character vector of unframed JSON replies. Notifications normally return character(0).

Details

The server uses the editor's text (including unsaved incremental changes) and the R packages available in the runtime. Definitions, references and rename consult open documents in the same workspace folder. Changes of workspace folders regroup unsaved buffers. Project-wide renames require a client that confirms annotated edits, except for lexical body locals and standalone workspaces containing only untitled buffers. Changes are applied immediately and parsed on demand before servicing a request. User scripts are never sourced. Pull diagnostics report R syntax errors and, when lintr is installed, its infix-spacing rule. They respect the diagnostics setting and do not load project lint configuration. A diagnostics backend other than lintr receives syntax diagnostics. Full-document formatting uses styler when installed. Native formatter/backend selection and other workspace configuration keys are not synchronized.

See also

run() for stdio and TCP transports, and the embedded host guide for an initialization and editing example.