[R] Using system() to dump HDF to text file?
William Dunlap
wdunlap at tibco.com
Tue Jan 15 20:21:52 CET 2013
Use shell() instead of system(). E.g., I have a bunch of Unix-like
executables in c:\cygwin\bin and I can use pipe and redirection
signs with them using shell():
> tf <- tempfile()
> file.exists(tf)
[1] FALSE
> shell(paste("c:\\cygwin\\bin\\ls | c:\\cygwin\\bin\\head -5 >", shQuote(tf, "cmd")))
> readLines(tf)
[1] "R.dll" "R.exe" "RSetReg.exe" "Rblas.dll" "Rcmd.exe"
> getwd()
[1] "C:/Program Files/R/R-2.15.2/bin/x64"
> dir()
[1] "open.exe" "R.dll" "R.exe" "Rblas.dll" "Rcmd.exe" "Rgraphapp.dll" "Rgui.exe" "Riconv.dll" "Rlapack.dll" "Rscript.exe" "RSetReg.exe"
[12] "Rterm.exe" "Rzlib.dll"
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Sarah Henderson
> Sent: Tuesday, January 15, 2013 10:28 AM
> To: R List
> Subject: [R] Using system() to dump HDF to text file?
>
> Hi all --
>
> I am working on 64-bit Windows XP. I'm not a very technical person when it
> comes to the command line stuff, so please forgive me if this is a stupid
> question.
>
> I have a bunch of HDF files, and I want to dump a single PM25 data layer
> from each file to .txt by invoking ncdump.exe from system(). Here's a
> sample command string:
>
> "C:/ncdump -v PM25 C:/01aug2010.hdf > C:/01aug2010.txt"
>
> This works perfectly in Python, but does not actually generate the .txt
> file in R when:
>
> system(command)
>
> It does show the output on the console, if flagged to do so, and I can
> capture the output to an R object with intern = T. I assume there is some
> problem with the way I have specified how to get the output to the text
> file (i.e. the ">"), but experimentation with other options has not gone
> well.
>
> Can anyone advise?
>
> Thanks!
>
> Sarah
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list