[TxMt] Extracting and Sending Data to the R GUI
Ana Nelson
nelson.ana at gmail.com
Mon Jul 3 08:41:48 UTC 2006
I often need to import data into R using the read.table command, but
my data files have header and footer information which shouldn't be
parsed by read.table. Here is a script which takes selected lines
from the active document and imports them to R using read.table:
-----
header_row_grep_text="run"
ignore_lines_at_end=2
# Find the header row, which always (and uniquely) contains the text
specified above.
X=`grep -n $header_row_grep_text $TM_FILEPATH | cut -f1 -d:`
# Determine the number of lines in file.
Y=`wc -l $TM_FILEPATH | cut -c 1-8`
# Tell R to read the data in this file, starting with line X which
has the variable names.
osascript -e 'tell application "R" to activate' -e "tell application
\"R\" to cmd \"data <- read.table(\\\"$TM_FILEPATH\\\", header=TRUE,
sep=\\\",\\\", skip=`expr $X - 1`, nrows=`expr $Y - $X -
$ignore_lines_at_end`)\""
-----
I have a more detailed explanation here: http://love.agent.ie/
articles/2006/07/02/sending-simulation-output-to-r
-Ana
More information about the textmate
mailing list