Learn R Programming

excel.link (version 0.9.13)

xl.read.file: Functions for saving and reading data to/from Excel file.

Description

Functions for saving and reading data to/from Excel file.

Usage

xl.read.file(
  filename,
  header = TRUE,
  row.names = NULL,
  col.names = NULL,
  xl.sheet = NULL,
  top.left.cell = "A1",
  na = "",
  password = NULL,
  write.res.password = NULL,
  excel.visible = FALSE
)

xl.save.file( r.obj, filename, row.names = TRUE, col.names = TRUE, xl.sheet = NULL, top.left.cell = "A1", na = "", password = NULL, write.res.password = NULL, excel.visible = FALSE, file.format = xl.constants$xlOpenXMLWorkbook )

Value

xl.read.file always returns data.frame. xl.save.file

invisibly returns NULL.

Arguments

filename

a character

header

a logical value indicating whether the file contains the names of the variables as its first line. If TRUE and top-left corner is empty cell, first column is considered as row names. Ignored if row.names or col.names is not NULL.

row.names

a logical value indicating whether the row names of r.obj are to be read/saved along with r.obj

col.names

a logical value indicating whether the column names of r.obj are to be read/saved along with r.obj

xl.sheet

character. Name of Excel sheet where data is located/will be saved. By default it is NULL and data will be read/saved from/to active sheet.

top.left.cell

character. Top-left corner of data in Excel sheet. By default is 'A1'.

na

character. NA representation in Excel. By default it is empty string.

password

character. Password for password-protected workbook.

write.res.password

character. Second password for editing workbook.

excel.visible

a logical value indicating will Excel visible during this operations. FALSE by default.

r.obj

R object.

file.format

integer. Excel file format. By default it is xl.constants$xlOpenXMLWorkbook. You can use xl.constants$xlOpenXMLWorkbookMacroEnabled for workbooks with macros (*.xlsm) or xl.constants$xlExcel12 for binary workbook (.xlsb).

Details

xl.read.file reads only rectangular data set. It is highly recommended to have all column names and ids in data set. Orphaned rows/columns located apart from the main data will be ignored. xl.save.file can save all objects for which xl.write method exists - see examples.

See Also

xl.write, xl.workbook.save, xl.workbook.open, current.graphics

Examples

Run this code


if (FALSE) {
data(iris)
xl.save.file(iris,"iris.xlsx")
xl.iris = xl.read.file("iris.xlsx")
all(iris == xl.iris) # Shoud be TRUE
unlink("iris.xlsx")

# Save to file list with different data types 
dists = dist(iris[,1:4])
clusters = hclust(dists,method="ward.D")
iris$clusters = cutree(clusters,3)
png("1.png")
plot(clusters)
dev.off()
pl.clus = current.graphics(filename="1.png")
cross = table(iris$Species,iris$clusters)
png("2.png")
plot(cross)
dev.off()
pl.cross = current.graphics(filename="2.png")
output = list("Iris",pl.clus,cross,pl.cross,"Data:","",iris)
xl.save.file(output,"output.xls")
xl.workbook.open("output.xls")
# xl.workbook.close() # close workbook
# unlink("output.xls") # delete file

# password-protected file
data(iris)
xl.save.file(iris,"iris.xlsx", password = "pass")
xl.iris = xl.read.file("iris.xlsx", password = "pass")
all(iris == xl.iris) # Shoud be TRUE
unlink("iris.xlsx")

}

Run the code above in your browser using DataLab