Using packages and functions in R

Using packages and functions in R

1. XLConnect. We use it to Read and manipulate excel files.

Description: A platform-independent interface to Excel. XLConnect is a package that allows for reading, writing and manipulating Microsoft Excel files from within R. It uses the Apache POI API 1 as the underlying interface. XLConnect allows you to produce formatted Excel reports, including graphics, straight from within R. This enables automation of manual formatting and reporting processes. Reading and writing named ranges enables you to process complex inputs and outputs in an efficient way.

A. Installing the package: install.packages(“XLConnect”) B. Load the package in R: library(XLConnect) Also if you need help run this command: help(“XLConnect”“) C. Load the excel workbook into R. loadWorkbook(filename, create=TRUE)

#Using the excel spreadsheet provided in the classroom, regarding the example of blood pressure.
library(XLConnect)
## Loading required package: XLConnectJars
## XLConnect 0.2-12 by Mirai Solutions GmbH [aut],
##   Martin Studer [cre],
##   The Apache Software Foundation [ctb, cph] (Apache POI, Apache Commons
##     Codec),
##   Stephen Colebourne [ctb, cph] (Joda-Time Java library),
##   Graph Builder [ctb, cph] (Curvesapi Java library)
## http://www.mirai-solutions.com ,
## http://miraisolutions.wordpress.com
help("XLConnect")
bloodp = loadWorkbook("bloodpress.xlsx", create=TRUE)
data = readWorksheet(bloodp, sheet = "systolic", startRow = 0, endRow = 10, startCol = 0, endCol = 0)
data
##   Nothing LowSalt WOSalt LowDose HighDose
## 1     180     172    163     158      147
## 2     173     158    170     146      152
## 3     175     167    158     160      143
## 4     182     160    162     171      155
## 5     181     175    170     155      160

We can also use the following functions: writeWorksheet(), createName(), writeNamedRegion(), saveWorkbook(), writeWorksheetToFile(), writeNamedRegion1ToFile(), among others.

2. XLSX. For direct manipulation of sheets, rows and cells of xlsx files.

Description: The xlsx package gives programatic control of Excel files using R. A high level API allows the user to read a sheet of an xlsx document into a data.frame and write a data.frame to a file. Lower level functionality permits the direct manipulation of sheets, rows and cells. For example, the user has control to set colors, fonts, data formats, add borders, hide/unhide sheets, add/remove rows, add/remove sheets, etc.

require(xlsx)
## Loading required package: xlsx
## Loading required package: rJava
## Loading required package: xlsxjars
## 
## Attaching package: 'xlsx'
## The following objects are masked from 'package:XLConnect':
## 
##     createFreezePane, createSheet, createSplitPane, getCellStyle,
##     getSheets, loadWorkbook, removeSheet, saveWorkbook,
##     setCellStyle, setColumnWidth, setRowHeight
dat <- read.xlsx("bloodpress.xlsx", sheetName = "systolic") # reading file from class.
dat
##   Nothing LowSalt WOSalt LowDose HighDose
## 1     180     172    163     158      147
## 2     173     158    170     146      152
## 3     175     167    158     160      143
## 4     182     160    162     171      155
## 5     181     175    170     155      160

3. RODBC. Implements ODBC database connectivity.

Description: The mainly internal odbc, commands implement low-level access to the ODBC functions of similar name. The sql functions operate at a higher level to read, save, copy and manipulate data between data frames and SQL tables. Many connections can be open at once to any combination of DSN/hosts.

4. gdata. Provides various R programming tools for data manipulation.

5. xlsReadWrite. Integrates R in excel function.

6. Rexcel. This function It is use to read an excel table in R.

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.