1 ### R code from vignette source 'ch-import-export.rnw'
3 ###################################################
4 ### code chunk number 1: ch-import-export.rnw:6-9
5 ###################################################
11 ###################################################
12 ### code chunk number 2: ch-import-export.rnw:19-24
13 ###################################################
15 save(a, file="./data/dumData.Rdata")
17 load("./data/dumData.Rdata")
21 ###################################################
22 ### code chunk number 3: ch-import-export.rnw:32-40
23 ###################################################
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")
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"
41 # filename should be no more than 8 characters, without extension
43 # read data from a SAS dataset
44 a <- read.ssd(file.path(filepath), fileName, sascmd=file.path(sashome, "sas.exe"))
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)
58 ###################################################
59 ### code chunk number 6: ch-import-export.rnw:107-114 (eval = FALSE)
60 ###################################################
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 ###################################################
74 ## filename <- "data/dummmyData.xls"
75 ## xlsFile <- odbcConnectExcel(filename, readOnly = FALSE)
76 ## sqlSave(xlsFile, a, rownames = FALSE)
77 ## b <- sqlFetch(xlsFile, "a")