[R] using the system command
Data Analytics Corp.
walt at dataanalyticscorp.com
Wed Sep 28 18:05:28 CEST 2011
Hi,
I started playing around with a function for using StatTransfer (version
10) for importing data. This started as a simple task but it's not
working and so now I'm very frustrated. I'm using R version 2.13 on
Windows 7.
The function, called fn.importData, is:
function(file = NULL, type = NULL){
##
## create statTransfer command file - stcmd
##
ext <- switch(type, sas = "sas7bdat", excel = "xls")
tmp <- paste("copy C:\\Temp\\", file, ".", ext, " r
c:\\temp\\", file, ".rdata -T > ", file, " \n\nquit", sep = "")
cat(tmp, file = "c:/temp/transfer.stcmd", append = FALSE)
##
## transfer using StatTransfer
##
system(paste('"c:\\program files\\statTransfer10\\st.exe"',
'c:\\temp\\transfer.stcmd'), wait = FALSE)
##
## load
##
inpt <- paste("c:\\temp\\", file, ".RData", sep = "")
##return(inpt)
load(inpt, .GlobalEnv)
}
My call using a sas file (vicks.sasa7bdat) is:
fn.importData(file = "vicks", type = "sas")
The StatTransfer command file is created and StatTransfer is called
correctly. The translation from vicks.sas7bdat to vicks.RData occurs
as it should - I can look at them in the temp directory. But I get an
error message for the load function:
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the
connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
cannot open compressed file 'c:\temp\vicks.RData', probable
reason 'No such file or directory'
If I uncomment the return(inpt) statement in the above function and use
the following at the command line:
load(fn.importData(file = "vicks", type = "sas"))
then everything works fine. But of course I don't want to do this. Any
suggestions as to what I'm doing wrong? Why the error message?
Also, the StatTransfer program sometimes fails to close so if I
repeatedly call my function I'll have multiple occurrences of
StatTransfer running. How can I force it to close after the transfer?
Thanks,
Walt
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
walt at dataanalyticscorp.com
www.dataanalyticscorp.com
More information about the R-help
mailing list