added Feb 2001 SDK
[windows-sources.git] / data-science-platform / R-code-for-RDataMining-book / ch-import-export.R
blob3f38de2de0b0d8c15864426f85d1eb1bce6ecbd8
1 ### R code from vignette source 'ch-import-export.rnw'
3 ###################################################
4 ### code chunk number 1: ch-import-export.rnw:6-9
5 ###################################################
6 # free memory
7 rm(list = ls())
8 gc()
11 ###################################################
12 ### code chunk number 2: ch-import-export.rnw:19-24
13 ###################################################
14 a <- 1:10
15 save(a, file="./data/dumData.Rdata")
16 rm(a)
17 load("./data/dumData.Rdata")
18 print(a)
21 ###################################################
22 ### code chunk number 3: ch-import-export.rnw:32-40
23 ###################################################
24 var1 <- 1:5
25 var2 <- (1:5) / 10
26 var3 <- c("R", "and", "Data Mining", "Examples", "Case Studies")
27 df1 <- data.frame(var1, var2, var3)
28 names(df1) <- c("VariableInt", "VariableReal", "VariableChar")
29 write.csv(df1, "./data/dummmyData.csv", row.names = FALSE)
30 df2 <- read.csv("./data/dummmyData.csv")
31 print(df2)
34 ###################################################
35 ### code chunk number 4: ch-import-export.rnw:71-80
36 ###################################################
37 library(foreign) # for importing SAS data
38 # the path of SAS on your computer
39 sashome <- "C:/Program Files/SAS/SASFoundation/9.2" 
40 filepath <- "./data"
41 # filename should be no more than 8 characters, without extension
42 fileName <- "dumData" 
43 # read data from a SAS dataset
44 a <- read.ssd(file.path(filepath), fileName, sascmd=file.path(sashome, "sas.exe"))
45 print(a)
48 ###################################################
49 ### code chunk number 5: ch-import-export.rnw:85-90
50 ###################################################
51 # read variable names from a .CSV file
52 variableFileName <- "dumVariables.csv"
53 myNames <- read.csv(paste(filepath, variableFileName, sep="/"))
54 names(a) <- names(myNames)
55 print(a)
58 ###################################################
59 ### code chunk number 6: ch-import-export.rnw:107-114 (eval = FALSE)
60 ###################################################
61 ## library(RODBC)
62 ## connection <- odbcConnect(dsn="servername",uid="userid",pwd="******")
63 ## query <- "SELECT * FROM lib.table WHERE ..."
64 ## # or read query from file
65 ## # query <- readChar("data/myQuery.sql", nchars=99999)
66 ## myData <- sqlQuery(connection, query, errors=TRUE)
67 ## odbcClose(connection)
70 ###################################################
71 ### code chunk number 7: ch-import-export.rnw:122-128 (eval = FALSE)
72 ###################################################
73 ## library(RODBC) 
74 ## filename <- "data/dummmyData.xls"
75 ## xlsFile <- odbcConnectExcel(filename, readOnly = FALSE)
76 ## sqlSave(xlsFile, a, rownames = FALSE)
77 ## b <- sqlFetch(xlsFile, "a")
78 ## odbcClose(xlsFile)