Category Archives: R

Bio7 2.4 for Windows and Mac Released

A new release of Bio7 is available for Windows and MacOSX. The Linux version will be released soon, too. This release comes with a plethora of new functions, especially for the R editor.

Download at:

Release notes:


  • Updated Bio7 to use Eclipse 4.6 (Neon) as RCP basis
  • Updated the embedded Java Runtime Environment to version 1.8.92
  • Updated embedded R for Windows to R 3.3.1
  • Improved the toolbar layout and action alignments (CSS can be edited!)
  • Added a new ImageJ R analysis perspective


  • Added a new R debug perspective
  • Added a new and easy to use text preference field to execute Groovy script commands at startup (beside any scripts in the startup folder!) to open, e.g., a custom perspective, or startup R  if enabled.


  • The Quadgrid, Linechart, Piechart and the Points view are now embedded in a Swt JavaFX panel and can be fullscreened (F1, F2, F3, F4, F5 – F1 key is Windows only!)
  • Added a terminate (Java controlled) and kill R process (OS controlled) action to the main toolbar of Bio7.


  • At R/Rserve startup a new check for a running R instance is executed with an option to kill all running R instances (to avoid a wrong connection to a running instance from an crashed Bio7 R session).
  • Added  many new Bio7 R command key shortcuts
  • Added an install R packages script to install some useful default R packages for Bio7

R editor:

  • The R editor has been transferred to it’s own Github repository and can be updated as a plugin
  • Improved and formatted the display of the error messages
  • Improved massively the speed for parsing and marker creation
  • Added many new R editor key shortcuts to speed up editing
  • Added an action to the context menu to open the plot preferences
  • Added an action to the context menu to open the font preferences
  • Added a RServe formatR action to the context menu
  • Added a Profile script action for the profvis package to the context menu
  • Added a Profile script selection action for the profvis package to the context menu
  • Added a color dialog to the context menu. A selected R,G,B color will be displayed and set in the editor
  • Added an “Reload Package Completion” action to the context menu to load completion help for loaded packages (decrease warnings by known methods, increase available code completion templates – The same action is available in the R-Shell view evaluation textfield).


  • The Load/Remove packages(s) dialog has a new action to transfer available selected package names to the R editor (as ‘library(package)’)
  • Now warnings and errors are displayed more consistently. If a quick fix is available it will be indicated with a warning/error quick fix icon instead of a default warning/error icon
  • Added new quick fixes to the R editor
  • Quick fixes and warning messages can now be displayed and fixed by hoovering over the underlined editor marker
  • Added the automatic close of {braces}, (parentheses), [brackets], “strings” and ‘strings’. It can be disabled in the preferences
  • Improved the speed of the ‘Mark selected word’ action (scope independant) which can be enabled in the preferences

R editor refactoring

  • Added an ‘Extract Method’ action which parses and extract a method from a selected text if valid


  • Added an ‘Extract Variable’ action which parses and extracts a variable from a selected text if valid
  • Added a ‘Create new File from Clipboard’ action which parses and creates a new file from the clipboard text if valid in the project folder and opens the R file for editing
  • Added an ‘Extract Editor Selection to File’ action which parses and creates a new file from a selection if valid in the project folder and opens the R file for editing

R editor code analysis:

  • Added an analysis function to detect Unused Functions
  • Added an analysis function to detect if a function is available
  • Added an analysis function to detect if a variable is used
  • Added an analysis function to detect if a variable is available
  • Added an analysis function to check for wrong constants (na, true, false, null)
  • Added an analysis function to check for functions if a function (or variable) with that name is already defined
  • Added an analysis function to check for variables if a variable (or function) with that name is already defined
  • Added an analysis function to check if a function call argument is missing
  • Added an analysis function to check if a function call has to many arguments
  • Added an analysis function to check if the name of a variable assignment in a function call is wrong
  • Added an analysis function to check a function call with parameter on a parameterless function
  • Added an analysis function to check variables in function calls and square brackets
  • Added options in the preferences to enable/disable the code analysis functions


R Outline View

  • Added the display of loop variables to the outline view
  • Added the display of function call variable assignments to the outline view
  • Added the display of S3,S4, References and R6 classes to the outline view (S3 classes are only detected with class(x), References classes and R6 classes functions are not displayed nested!)


R editor code completion

  • The sorting of the code completion dialog has been improved
  • The code completion dialog now displays local defined variables and methods available in the current scope
  • Added a new function in the code completion popup dialog to open the template preferences faster


  • If the code completion is opened in a method call the arguments of the function will be displayed in a new table dialog. However if an function or variable is started within the method call the regular code completion is shown (for nested functions or variables call)


  • Added two actions in the hoover help dialog to open the help browser (?) or search in the Rdocumentation website


  • The code completion dialog can now be configured in the preferences to open automatically on key typing  (number of typed chars and chars can be configured, too).

R-Shell view

  • The R text is now validated with the Bio7 default R code parser
  • Added an error marker to the textfield if a parsing error occurs
  • Added code completions to the evaluate expression textfield (Ctrl+Space). Code completion is only available in nested calls after open parentheses


  • A help file browser can now be opened from selected text (e.g., nested function).
  • Native connection commands can now be executed in the evaluate expression textfield

R Markdown

  • Now JavaScript is enabled for the HTML-Browser by default
  • Added a new option to scale the JavaFX browser content if enabled  (handy for R markdown presentations). The JavaFX  browser can be fullscreened (F1,F2,F3 – secondary monitor…..)

Table view

  • Improved massively the speed of the close operation of a table sheet
  • Improved the CSV importer with more options to import data with a dynamic preview
  • The CSV importer now accepts clipboard data if selected
  • The preview table is now updated dynamically if changes occur



  • Updated ImageJ to version 1.51d
  • Added a subset of ImageJ2 libraries in a new ImageJ2 Eclipse plugin
  • Improved the ROI image pixel data transfer methods. Now selected ROI’s pixels are transferred. If no selection is available all ROI‘s will be transferred!
  • The ROI transfer methods now also accept points and lines (please note that line pixels are interpolated in the ImageJ results table by default)
  • The Bio7 ImageJ plugin can now be updated or installed individually
  • ImageJ panels can now be opened in a JavaFX panel embedded in SWT (experimental) if enabled in the preferences


  • Updated all Java libraries
  • Update the JavaFX SceneBuilder to version 2.2
  • The JavaFX SceneBuilder controller class created variables and methods are now ‘public’ by default.
  • Added support for LibreOffice 5. Now the Bio7 LibreOffice functions work again with LibreOffice 5.

Eclipse Neon features



Just download the *.zip distribution file from and unzip it in your preferred location. Bio7 comes bundled with the latest Java Runtime Environment, R and Rserve distribution and works out of the box.


Just download and execute the *.dmg installation file from

To use R and Rserve you have to install R for MacOSX.

In addition you have to install Rserve configured to use ‘cooperative mode’ (shared workspace in Rserve and R mode) which can be downloaded here:

In the R prompt type the following command to install the compiled package (replace with your file path!):

install.packages(“Users/yourName/Downloads/Rserve_1.8-4_Mac_cooperative.tgz”, repos=NULL)

You can also compile Rserve by yourself. For an HowTo please consult the Bio7 documentation here.


Added a tiny script to install useful default R packages for Bio7 to use all available GUI functionalities (e.g. rmarkdown, rgdal, spatstat, formatR, knitr, etc.). To install the scripts start Rserve and execute the action Scripts->RScripts->Install_R_Packages.

The script will install the R packages.

For MacOSX it could be that you have to select a mirror in the Bio7 Console (shell). Type in a number (1- …) and press return to start the installation if no shell message is displayed. The R installation script can be edited in /plugins/ Suggestions for improvements are welcome.



R editor improvements for the next release of Bio7


For the upcoming release of Bio7 I worked hard to improve the R editor features. So I added some new features and improvements to assist in the creation of R scripts in Bio7.
One of the highlights is the newly integrated dynamic code analysis when writing an R script.

Here a short overview of some new R editor features I integrated so far:

  • Detect and display unused variables and functions


  • Detect missing functions and variables
  • Added a new code assist list when triggered in function calls


  • Check of function arguments


  • Check of wrong function argument


  • Available help for mistyped functions (% similarity)


  • Improved Code Completion in general
  • Added a toolbar with two HTML help actions to the context help dialog (if you hover over a method)


  • Improved Code Completion to list local scope self defined variables and functions


  • Added  an refactor action to extract variables
  • Added an refactor action to extract functions


  • Added more Quickfixes
  • Quickfixes can now be opened by hovering over a problem or error marker
  • Added an automatic close action of parentheses, brackets, braces and strings in the editor
  • Improved the general parsing speed
  • Added new key shortcuts to faster perform R editor actions
  • New action and key shortcut to open the plot preferences faster
  • Added new on/off preferences for the new features
  • Improved the display of the Outline view for variables and functions

There is of course some room for improvements and there are some rough edges in the implementation of the dynamic code analysis since the R language is a highly dynamic language. However I hope that this features will be a help in the creation of correct R scripts in the R editor of the next Bio7 release.

Supervised Image Classification With Bio7, R And ImageJ


I created a new Bio7 example which demonstrates how to classify an image with Bio7, ImageJ and R.


For the classification I used the “randomForest” R package and an image example of ImageJ so you can reproduce the example quite easily. I made the example script as easy as possible and trained the classifier with 64 trees by default (see literature below). Not shown in the video is the procedure to control the prediction of the trained classifier with test data. You can find a simple script in the repository, too, which uses a method of the powerful ‘caret’ package.


If you have some recommendations of how to effectively use a decent classifier for image classification (e.g., which classifier is well suited for images, which tuning parameters are useful in this context, which additional signatures could be used, etc.) I would be happy to hear.


Fernández-Delgado, M., Cernadas, E., Barro, S. & Amorim, D. Do we Need Hundreds of Classifiers to Solve Real World Classification Problems? Journal of Machine Learning Research 15, 3133–3181 (2014).

Oshiro, T. M., Perez, P. S. & Baranauskas, J. A. in Machine Learning and Data Mining in Pattern Recognition (ed. Perner, P.) 154–168 (Springer Berlin Heidelberg, 2012).

Latinne, P., Latinne, P., Debeir, O. & Decaestecker, C. Limiting the Number of Trees in Random Forests. IN PROCEEDINGS OF MCS 2001, LNCS 2096, 2001.

New R plot preferences and improvements for the R editor in Bio7


In the current release of Bio7 2.3  two new plot preferences are available to automatically plot data with the size of the visible display (as an image) or with the size of available ImageSizeX and ImageSizeY R workspace variables.

The second option is handy if you transfer images from ImageJ to the R workspace (the variables ImageSizeX and ImageSizeY will be autmatically created, too). You can then create an R image plot (e.g. from a classification) in the same size as an overlay of the original image (in turn plotted and overlayed in ImageJ).


Improvements of the  R editor for the upcoming Bio7 2.4 release

For the upcoming release of Bio7 I also add new features to the Bio7 R editor.

Among other things until now I improved the code completion. If you now type a a left parenthesis you get a help tooltip if the function is known (if you load frequent used R packages with the Bio7 GUI interface the package function context will be added to the code completion, tooltip interface).


Screenshot 1: Improved tooltip when a left parenthesis is typed.


Figure 2: Code completion (Keys: CTRL+Space) now preselects the right context (e.g. functions with ‘.’ char)

In addition I added a function to set right parentheses, braces, etc. automatically when left parentheses, etc.  are typed in the R editor.

Spatstat – An introduction and measurements with Bio7


Here I present a summary of a small spatstat workshop I created. I also explain in several videos how to transfer and convert 2d and 3D ImageJ measurements to a spatial point pattern with Bio7. The example datasets and code samples used here were taken from the spatstat help and from spatstat scripts cited at the end of the summary. The github repository with spatstat scripts, image scripts, documentation and more can be found here. I hope that this material is useful for others and helps in the creation of a spatial point pattern analysis with the fantastic spatstat package.


From the spatstat website:

‘spatstat is a package for analyzing spatial point pattern data. Its functionality includes exploratory data analysis, model-fitting, and simulation.’ (1)

The package supports:

  • creation, manipulation and plotting of point patterns
  • exploratory data analysis
  • simulation of point process models
  • parametric model-fitting
  • hypothesis tests and model diagnostic

Classes in spatstat

To handle point pattern datasets and related data, the spatstat package supports the following classes of objects:

  • ppp: planar point pattern
  • owin: spatial region (‘observation window’)
  • im: pixel image
  • psp: pattern of line segments
  • tess: tessellation
  • pp3: three-dimensional point pattern
  • ppx: point pattern in any number of dimensions
  • lpp: point pattern on a linear network

Creation of a point pattern object

A point pattern object can be created easily from x and y coordinates.

library (spatstat)
# some arbitrary coordinates in [0,1]
x <- runif(20)
y <- runif(20)
# the following are equivalent
X <- ppp(x, y, c(0,1), c(0,1))
X <- ppp(x, y)
X <- ppp(x, y, window=owin(c(0,1),c(0,1)))
# specify that the coordinates are given in metres
X <- ppp(x, y, c(0,1), c(0,1), unitname=c("metre","metres"))

Study region (window)

Many commands in spatstat require us to specify a window, study region or domain!

An object of class “owin” (‘observation window’) represents a region or window (rectangular, polygonal with holes, irregular) in two dimensional space.


w <- owin(c(0,1), c(0,1))
# the unit square
w <- owin(c(10,20), c(10,30), unitname=c("foot","feet"))
# a rectangle of dimensions 10 x 20 feet
# with lower left corner at (10,10)

# polygon (diamond shape)
w <- owin(poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1)))
w <- owin(c(0,1), c(0,2), poly=list(x=c(0.5,1,0.5,0),y=c(0,1,2,1)))
# polygon with hole
  ho <- owin(poly=list(list(x=c(0,1,1,0), y=c(0,0,1,1)),
     list(x=c(0.6,0.4,0.4,0.6), y=c(0.2,0.2,0.4,0.4))))



Task 1: Create a point pattern object from x,y data.

Task 2: Create a point pattern object within a specified window object.

Example dataset


Summary statistics of the dataset


## Planar point pattern:  71 points
## Average intensity 0.007395833 points per square unit (one unit = 0.1 
## metres)
## Coordinates are integers
## i.e. rounded to the nearest unit (one unit = 0.1 metres)
## Window: rectangle = [0, 96] x [0, 100] units
## Window area = 9600 square units
## Unit of length: 0.1 metres

Computes the distance from each point to its nearest neighbour in a point pattern.


##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.236   5.541   8.246   7.908  10.050  15.650

Finds the nearest neighbour of each point in a point pattern.

m <- nnwhich(cells)
m2 <- nnwhich(cells, k=2)
#Plot nearest neighbour links
b <- cells[m]
arrows(cells$x, cells$y, b$x, b$y, angle=15, length=0.15, col="red")

Density plot:

plot(density(swedishpines, 10))

Contour plot of the dataset

contour(density(X,10), axes=FALSE)

How to create point data from an ImageJ particle analysis and Bio7

  1. Open an image dataset (we open the blobs.gif example image from the internet)
  2. Threshold the image
  3. Make a Particle Analysis (Analyze->Analyze Particles…). Select the option ‘Display results’
  4. Transfer the Results table data with the Image-Methods view action ‘Particles’ (ImageJ-Canvas menu: Window->Bio7-Toolbar – Action: Particles)
  5. Execute the R script below

#Plot is visualized in ImageJ (Java) coordinates!
X<- ppp(Particles$X, Particles$Y, c(0,imageSizeX), c(0,imageSizeY))
plot(x = 1, y = 1,xlim=c(0,imageSizeX),ylim=c(imageSizeY,0), type = "n", main = "blobs.gif", asp = 1, axes = F, xlab = "x", ylab = "y")
plot(X,axes=TRUE,xlim=c(1,imageSizeX),ylim=c(imageSizeY,1),add = T)
axis(2, las = 2)

We can also plot the points as an overlay (Script just for plotting – normally image data for spatstat has to be converted!).

im<, owin(xrange=c(0,imageSizeX), yrange=c(0,imageSizeY)))
#Plot is visualized in ImageJ (Java) coordinates!
plot(x = 1, y = 1,xlim=c(0,imageSizeX),ylim=c(imageSizeY,0), type = "n", main = "", asp = 1, axes = F, xlab = "x", ylab = "y"),add=T)
plot(X,xlim=c(0,imageSizeX),ylim=c(imageSizeY,0),add = T)

Video 1: Create a spatstat point pattern from a particle analysis

Video 2: Create a spatstat point pattern from SpatialPoints

Task 1: Create a spatstat object from the image example ‘Cell_Colony.jpg’.

Task 2: Create a density plot from the image ‘Cell_Colony.jpg’.

Task 3: Create a contour plot from the image ‘Cell_Colony.jpg’.

A polygonal window with a point pattern object can also be created with the ‘Image-Methods’ view action ‘Selection’ which opens a view to transfer different type of ImageJ selections as spatial data.

  1. Open the ‘Image-Methods’ view and execute the action ‘Selection’
  2. Open the blobs.gif example and make a polygonal selection
  3. Add the selection to the ROI Manager
  4. Transfer the selection with an enabled ‘Spatial Data’ option as a ‘Spatial Polygons’ – this will create the variable ‘spatialPolygon’ in the R workspace
  5. Convert the SpatialPolygon to a spatstat window object
  6. Threshold the image and execute the ‘Particle’ action in the Image-Methods view
  7. Make a Particle analysis with Bio7 and ImageJ
  8. Plot the particles with the polygonal window

The plot in R coordinates (0,0 in lower left)!


## Loading required package: sp
## Checking rgeos availability: TRUE

polWin<-as(spatialPolygons, "owin")


X<- ppp(Particles$X, Particles$Y,window=polWin)

Video: Create a spatstat point pattern with a polygonal window (study region)

Task 1: Create a polygonal point pattern object from the image ‘Cell_Colony.jpeg’.

Marked point patterns

Points in a spatial point pattern may carry additional information called a ‘mark’. A mark can represent additional information like height, diameter, species, etc. It is important to know that marks are not covariates (the points are not a result of the mark values!).

#from the spatstat help:
# marks
m <- sample(1:2, 20, replace=TRUE)
m <- factor(m, levels=1:2)
X <- ppp(x, y, c(0,1), c(0,1), marks=m)


With Bio7 and ImageJ marked point patterns can be created with the ‘Selection’ action which can transfer a SpatialPointDataFrame which again can be converted to a marked point pattern.

  1. Select points and transfer the selections to the ROI Manager
  2. Measure the selections and transfer the ImageJ Results Table to R with the Image-Methods view ‘IJ RT’ action
  3. Transfer the points of the ROI Manager as a SpatialPointsDataFrame (Enable the ‘Add selected data frame’ option and select the dataframe in the combobox)
  4. Convert the SpatialPointsDataFrame to a spatstat point pattern object with the results table as marks

spatialPointsDF<-as(spatialPointsDataFrame, "ppp")


#print a summary!

## Marked planar point pattern:  8 points
## Average intensity 0.0002494232 points per square unit
## Coordinates are integers
## i.e. rounded to the nearest unit
## Mark variables: Area, Mean, Min, Max, X, Y
## Summary:
##       Area        Mean          Min           Max            X        
##  Min.   :0   Min.   :160   Min.   :160   Min.   :160   Min.   : 75.0  
##  1st Qu.:0   1st Qu.:190   1st Qu.:190   1st Qu.:190   1st Qu.:124.9  
##  Median :0   Median :220   Median :220   Median :220   Median :198.5  
##  Mean   :0   Mean   :209   Mean   :209   Mean   :209   Mean   :173.1  
##  3rd Qu.:0   3rd Qu.:232   3rd Qu.:232   3rd Qu.:232   3rd Qu.:221.0  
##  Max.   :0   Max.   :248   Max.   :248   Max.   :248   Max.   :233.5  
##        Y         
##  Min.   : 27.50  
##  1st Qu.: 63.25  
##  Median :119.25  
##  Mean   :129.06  
##  3rd Qu.:204.38  
##  Max.   :230.00  
## Window: rectangle = [75, 233] x [27, 230] units
## Window area = 32074 square units

You can also transfer a dataframe from the Table view of Bio7 (rows must be equal to the number of points!) and assign it to the point pattern.

Video: Create a spatstat marked point pattern:

Task 1: Create a marked point pattern from the image ‘Cell_Colony.jpg’.

Task 2: Create a marked point pattern from spreadsheet data in Bio7.


Tropical rainforest point pattern dataset bei. We want to find out if trees prefer a steep or flat terrain. The data consists of extra covariate data in ‘bei.extra’, which contains a pixel image of terrain elevation and a pixel image of terrain slope.

slope <- bei.extra$grad
par(mfrow = c(1, 2))



Exploratory data analysis

Quadrat count:

Z <- bei.extra$grad
b <- quantile(Z, probs = (0:4)/4)
Zcut <- cut(Z, breaks = b, labels = 1:4)
V <- tess(image = Zcut) 
plot(bei, add = TRUE, pch = "+")


qb <- quadratcount(bei, tess = V)

The plot below is an estimate of the intensity p(z) as a function of terrain slope z. It indicates that the Beilschmiedia trees are relatively unlikely to be found on flat terrain (where the slope is less than 0.05) compared to steeper slopes.

plot(rhohat(bei, slope))

Quadrat counting

The study region is divided into rectangles (quadrats) of equal size, and the number of points in each rectangle is counted.

Q <- quadratcount(X, nx = 4, ny = 3)

##                x
## y               [0,0.25] (0.25,0.5] (0.5,0.75] (0.75,1]
##   (0.667,1]            0          2          1        3
##   (0.333,0.667]        2          2          2        1
##   [0,0.333]            0          1          2        4

plot(Q, add = TRUE, cex = 2)

Ripley’s K function

K <- Kest(X)

L function (common linear transformation of K)

  • lines below theoretical line -> over-dispersion
  • lines above theoretical line -> aggregation

L <- Lest(X)
plot(L, main = "L function")

Generate an envelope for the K and L function

ENV <- envelope(Y = swedishpines, fun = Kest, nsim = 40)

## Generating 40 simulations of CSR  ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
## 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
## 31, 32, 33, 34, 35, 36, 37, 38, 39,  40.
## Done.


ENVL <- envelope(Y = swedishpines, fun = Lest, nsim = 40)

## Generating 40 simulations of CSR  ...
## 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
## 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
## 31, 32, 33, 34, 35, 36, 37, 38, 39,  40.
## Done.


Task 1: Analyze the image example ‘Cell_Colony.jpg’ with the K and the L function.


Creation of line patterns

linePattern <- psp(runif(10), runif(10), runif(10), runif(10), window=owin())

Video: Create a spatstat line pattern

Dirichlet Tessellation of point pattern

X <- runifpoint(42)
plot(X, add=TRUE)

Point patterns in 3D

threeDPpp <- pp3(runif(10), runif(10), runif(10), box3(c(0,1)))

Video: Create a 3D point pattern from SpatialPoints measurements

Nearest neighbour measurements in 3D


##  [1] 0.3721581 0.1554657 0.2885439 0.1554657 0.5179962 0.6377469 0.1899220
##  [8] 0.2733618 0.1785442 0.1785442

Ripley’s K in 3D

threeDPppKest <- K3est(threeDPpp)

Point pattern example on a Linear Network (e.g. car accidents on a road)

Xlin <- rpoislpp(5, simplenet)

Fit a point process model to an observed point pattern.

# fit the stationary Poisson process
# to point pattern 'nztrees'

## Extracting model information...Evaluating trend...done.
## Checking arguments..determining simulation windows...

plot(modelFitted, main="Fitted Model")


Used for this script:

(1) A. Baddeley and R. Turner. Spatstat: an R package for analyzing spatial point patterns Journal of Statistical Software 12: 6 (2005) 1-42. ISSN: 1548-7660

(2) A. Baddeley and R. Turner. Modelling spatial point patterns in R. Chapter 2, pages 23-74 in In Case Studies in Spatial Point Pattern Modelling (eds. A. Baddeley, P. Gregori, J. Mateu, R. Stoica and D. Stoyan) Lecture Notes in Statistics 185. New York: Springer-Verlag 2006. ISBN: 0-387-28311-0

(3) A. Baddeley. Analysing Spatial Point Patterns in R. Workshop Notes, December 2010. Published online by CSIRO, Australia. Download here (232 pages, pdf, 12.2Mb)