This is an old revision of the document!
Table of Contents
How to write the R script for JUICE?
JUICE exports data into R via the bin folder of R installation (usually at c:/Program files/R/R-x.x.x/bin), and these data could be automatically loaded by appended R script. Files, which should be exported from JUICE, could be either manually selected in JUICE-R wizard, or could be selected automatically according to JUICE-R tags in R script header. The script, which is uploaded into R from JUICE, has two parts:
- the part created and appended automatically by JUICE, which contains script for uploading data exported from JUICE into appropriate R variables;
- the part created by the user, which contains the original R script.
JUICE part of the script
The complete R script, which JUICE automatically appends to the script file and which is intended for import of the data from JUICE to R, has the following structure:
setwd("C:/Program Files/R/R-x.xx.x/bin/") JUICE.table <- read.table ('table.txt', sep = '\t', check.names = F, head = T, row.names = 1) JUICE.short.head <- read.table('ShortHead.txt', sep='\t', head = T) JUICE.species.data <- read.table ('SpeciesData.txt', sep='\t', head = T) JUICE.head <- read.table ('TableHead.txt', sep='\t', head = T)
The files which JUICE exports in current session depends on which data are being exported. The command setwd sets the R working directory, into which the JUICE files are exported and from which R can read them.
Files exported from JUICE into R
| Original file name 1) | Name of variable in R | Content | Original file format 2) | Format of variable in R 3) |
|---|---|---|---|---|
| table.txt | JUICE.table | sample x species matrix | samples in rows, species in columns; first row - species names4)), first column - releve numbers | samples in rows, species in columns, releve numbers as rownames, species names as names |
| ShortHead.txt | JUICE.short.head | short header data | samples in rows, three columns with names Releve_Number, Group_Number, Short_Head | samples in rows, short header data in columns (Releve_Number, Group_Number and Short_Head) |
| SpeciesData.txt | JUICE.species.data | data associated to species | species in rows, ten columns with names SpecName_Layer, Species_name, Layer, Species_Data and species Ellenberg indicator values: Ellenberg_Light, Ellenberg_Temperature, Ellenberg_Continentality, Ellenberg_Moisture, Ellenberg_Soil_Reaction and Ellenberg_Nutrients | species in rows, species attributes in columns (SpecName_Layer, Species_name, Layer, Species_Data, Ellenberg_Light, Ellenberg_Temperature, Ellenberg_Continentality, Ellenberg_Moisture, Ellenberg_Soil_Reaction and Ellenberg_Nutrients) |
| TableHead.txt | JUICE.head | (long) header data | samples in rows, first two columns are Table number and Releve number, other columns and their names depends on the original JUICE file | samples in rows, header data as columns (first two are Table.number and Releve.number) |
User's part of the script
The script written by the user and stored in the file with *.r extension. It consists of following parts:
- header information
- JUICE-R tags (setting of export options in JUICE)
- the body of the script
1. Header information
Contains important information about the script. Follow this format (# at the beginning is important - R will ignore this line):
# Name: short name of the script # Author: Firstname Lastname (email@where.to.complain) # Description: brief description what is it doing # Version: version number (starts with 1.0, after minor revision it becomes 1.1, after major 2.0) # Date: when was the script posted
2. JUICE-R tags
The function of these tags is to set up particular switches for export of JUICE data into R. JUICE reads these tags while loading the script.
| Tag name | Tag function - what JUICE should do |
|---|---|
| JUICE.table | export sample x species matrix into table.txt file; R will read it as JUICE.table |
| JUICE.short.head | export short head into ShortHead.txt; R will read it as JUICE.short.head |
| JUICE.species.data | export species attributes into SpeciesData.txt; R will read it as JUICE.species.data |
| JUICE.head | export (long) header data into TableHead.txt; R will read it as JUICE.head |
| Rgui.exe | the script will run in interactive mode in R GUI |
| R.exe | the script will run in batch mode in R.exe |
| no.transf | sample x species data will not be transformed (the transformation setting will be ignored) |
The line with tags MUST begin with # JUICE-R (this is the sign for JUICE that JUICE-R tags follows) and should be located within the first 10 lines of the R script. Tags must be separated by space, and their order does not matter. Example, which will export sample x species data, header data and run the script in interactive mode (Rgui.exe).
# JUICE-R JUICE.table JUICE.head Rgui.exe
3. The body of the script
This part is up to the R script creater. Try to make it convenient for the user! See tips for writing the R script for JUICE-R.
