Skip to content


lunaR is a package for the R statistical software environment, which aims to provide a simple interface for the Luna library. Primary use cases are 1) for working with individual sleep studies/EDFs, and 2) as a convenient way to work with destrat output databases. For larger projects, the command-line version of Luna (lunaC) will likely be a better option.


To install lunaR, see the main installation pages, or try using the Dockerized version of Luna.


This page gives an overview of the core functions provided by this package, followed by examples and descriptions of some additional convenience functions. All examples on the page use the tutorial dataset, especially the second individual (nsrr02). The Luna tutorial also includes a section in which all steps are performed in lunaR as well as lunaC.

lunaR is simply an interface to the identical C/C++ library that underlies the lunaC command line tool: as such, lunaC and lunaR are fundamentally similar in most core respects. The different interfaces do mean that some aspects of the workflow differ between the two tools, however. For example, like lunaC, lunaR operates on a single EDF at a time; unlike the command line tool, however, lunaR is more interactive, in the sense that the modifiable, in-memory representation of the EDF typically persists between different lunaR commands. We discuss these differences below in more detail.


In this documentation, we refer to Luna's R interface as lunaR to distinguish it from the base Luna library and command-line tool, which we're calling lunaC. The actual R package is named luna however (as a lunar package already exists in CRAN), as is the command line you'll actually type (i.e. luna) to run lunaC.

The L-functions (i.e. all starting with the letter l for Luna) can be roughly grouped as follows:

The index below gives a listing of all major lunaR functions:

Function Description
lsl() Loads a sample list
lattach() Attaches an EDF from a sample list
ledf() Attaches an EDF directly
lstat() Reports on the currently attached EDF
ldrop() Detaches the current EDF
lrefresh() Reverts to the original attached EDF
lchs() Returns a vector of channel names for the attached EDF
ldata() Extracts signal (and annotation) data from an EDF for one or more epochs
ldata.intervals() Extracts signal (and annotation) data from an EDF for one or more intervals
lannots() Returns a vector of annotation class names for the attached EDF
lepoch() Epochs the data
letable() Returns an epoch-table with information about epochs, masks and annotations
lstages() Return vector of sleep stages from annotations
ladd.annot() Attaches an new annotation from an R interval list
ladd.annot.file() Attaches an new annotation from an file
leval() Evaluates an arbitrary set of Luna commands
leval.project() Evaluates an arbitrary set of Luna commands for all members of a project
lcmd() Reads and parses a Luna command script from a file
literate() Applies an arbitrary R function to signal data, one epoch or interval at a time
ldb() Imports data from a lout database as an R list object
lx() Extracts table(s) from objects returned by ldb(), leval() or `leval.project()
lx2() Like lx() but for lists of returned objects
lid() Extract a particular individual from a returned data frame
ltxttab() Loads and conconcatenates multiple text-table output files
lstgcols() Maps typical stage labels to colors (for plotting)
lbands() Splits a signal into five band-pass filtered signals
llog() Turns Luna's typical console messages on/off
le2i() Converts epochs to intervals
lsanitize() Cleans syntax of command, factor/level and channel names
ldenoise() 1D total variation denoiser
lheatmap() Plots heatmaps, e.g. for spectrograms
ltopo.heat() Topoplot (sensor-level)
ltopo.rb() Topoplot (sensor-level) with red-white-blue
ltopo.xy() Topoplot (sensor-level) X-Y plots
ltopo.heat2() Topoplot (sensor-level) of X-Y-Z heatmaps
ltopo.conn() Topoplot (sensor-level) of pairwise connectivity
ltopo.dconn() Topoplot (sensor-level) of single-sensor seeded connectivity
ltopo.topo() Topoplot (sensor-level) of topoplots
ltopo.topo() Topoplot (sensor-level) of topoplots
ltopo.topo() Topoplot (sensor-level) of topoplots
ldefault.xy() Default XY channel locations for plotting
ldefault.coh.xy() Default XY channel locations for coherence/connectivity plots
Back to top