Skip to content

k-barton/komodor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Komodo.R logo

Provides R language support and interface between R environment and Komodo.



This extension forked from “Sciviews-K” by Philippe Grosjean, and since then has been largely rewritten.

Features:

  • Connect to “R” session from Komodo (R application runs independently)
  • Execution of R code directly from within editor:
    • output from R is shown in the Command Output pane (new: real-time output in version 0.4)
    • execute (or source) the current line or selection, bookmark-delimited block, function under the cursor, or a whole file.
  • Syntax highlighting:
    • R language including Roxygen tags
    • R documentation (.Rd files, partially implemented)
    • Rmarkdown (.Rmd files, partially implemented)
  • Code completion (objects, argument names, list items)
  • Syntax checking
  • R object browser pane with fully expandable tree for inspecting user workspace and packages, objects' structure, including hidden objects, attributes, and function body.
  • Toolbar with commonly used commands
  • R help window (and simple web browser with and option to run selected text as R code)
  • R package manager
  • R working directory can be changed from Places pane (in the context menu)

R Interface screenshot

This add-on provides a file type named “R_extended” to avoid conflict with Komodo's built-in R syntax highlighter. Code completion and syntax checking works only with “R_extended” not “R”.

No additional R packages are required, however your R installation needs to have Tcl capability (by default it does. In R, check it with capabilities("tcltk")). See also Known issues below.

Other, obscure features:

  • Places panel:

    • load workspace from “.RData” files or source script from “.R” files: select a command from the context menu.
  • R browser:

    • drag an item to the editor to insert R objects' names, * hold "Shift" key during the drag start to drop quoted names,
      * hold "Ctrl" key during the drag start to drop full object names (e.g. list$data$column. Non-syntactic names will be backtick-quoted). * hold "Ctrl+Shift" to insert “name()” for functions or “name=” for function arguments.
    • filter items either by object name or class name (toggle the filter by button), using regular expressions. Prefix the search term with "~" to filter out matching names.
    • modify the function code or R expression by deleting its elements. Enable browsing of a function body (Depress the eye button and check the option under the cog menu), and navigate to the <function body> item located after the function arguments (an argument can be removed as well). It is not possible to modify functions inside packages or locked environments.
  • R search path box:

    • drop a package name onto it to load the package;
    • press "delete" to unload the selected package;
    • drag an item to the editor to insert package name.
  • R help window:

    • press Ctrl+R to run selected text in R (or choose the command from the context menu).
  • Editor:

    • Make code blocks foldable by putting #{{ and #}} around them (at the beginning of a line);
    • While in an R_extended document, press Shift+F1 once to search for the selected keyword in the loaded packages. Press Shift+F1 again to search in all packages.
  • The R tools toolbox has some more or less useful commands:

    • R markdown preview;
    • Insert result of the selected text evaluated in R;
    • Color picker (inserts hex code to the text);
    • Duplicate line or selection (assign to Ctrl+D to restore the good old pre-8 behaviour).
    • Smart highlight” marks all occurences of the word under the cursor in the current document.

Debugging R code

The extension provides some code debugging capabilities, see Debugging R code.

Main API functions

  • in Komodo: kor.r.evalUserCmd JavaScript function sends a command to R.
  • in R: koCmd executes a JavaScript command in Komodo and returns the result if any.
  • For more advances uses, CommonJS module "kor/r" (or kor.r object in the main window) has functions to perform various tasks via R, and the "kor/connector" module has more low level functions for communication between R and Komodo, of which require("kor/connector").evalAsync(command, callback) is the most useful.

Known issues:

  • Using browser and recover R commands causes a break in the transfer of output from R to Komodo. See Debugging R code.
  • Calculation can be interrupted only in the R window (Ctrl+C in R terminal, Escape key in RGui)
  • On MAC OS X: problems with starting R.app and connection with R
  • On Windows: Executing Rgui's command “Stop all computations” will also stop R's socket server and hence break the connection with Komodo. In rare cases, tt may also cause R to crash.
  • On Linux: Tk-Gui sometimes does not close properly. It is not recommended to use Tk-Gui with this add-on.
  • In rare cases, there may be problems with connection between R and Komodo server which cause R not to exit properly and it is necessary to manually kill the R process.
  • Syntax highlighting: when R is a sub-language (in Rd or Rmarkdown files), the colouring dissappears occassionally. There is also some flickering inside Roxygen comments. This is due to a bug in Komodo related to brace counting.