The excel.link package mainly consists of two rather independent parts: one is for transferring data/graphics to running instance of Excel, another part - work with data table in Excel in similar way as with usual data.frame.
Package provided family of objects:
xl
, xlc
, xlr
and
xlrc
. You don't need to initialize these objects or to do any
other preliminary actions. Just after execution library(excel.link)
you can transfer data to Excel active sheet by simple assignment, for
example: xlrc[a1] = iris
. In this notation 'iris' dataset will be
written with column and row names. If you doesn't need column/row names
just remove 'r'/'c' letters (xlc[a1] = iris
- with column names but
without row names). To read Excel data just type something like this:
xl[a1:b5]
. You will get data.frame with values from range a1:a5
without column and row names. It is possible to use named ranges (e. g.
xl[MyNamedRange]
). To transfer graphics use xl[a1] =
current.graphics()
.
You can make active binding to Excel range:
xl.workbook.add()
xl_iris %=crc% a1 # bind variable to current region around cell A1 on Excel active sheet
xl_iris = iris # put iris data set
identical(xl_iris$Sepal.Width, iris$Sepal.Width)
xl_iris$test = "Hello, world!" # add new column on Excel sheet
xl_iris = within(xl_iris, {
new_col = Sepal.Width * Sepal.Length # add new column on Excel sheet
})
For example we put iris datasset to Excel sheet:
xlc[a1] = iris
. After that we connect Excel range with R object:
xl_iris = xl.connect.table("a1",row.names = FALSE, col.names =
TRUE)
. So we can:
get data from this Excel range: xl_iris$Species
add new data to this Excel range: xl_iris$new_column = 42
sort this range: sort(xl_iris,column = "Sepal.Length")
and more...
Live connection is faster than active binding to range but is less universal
(for example, you can't use within
statement with it).
xl
, current.graphics
,
xl.connect.table