file handles in R

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

file handles in R

Albert-Jan Roskam
Hi,

In Python one can easily access file handles, and with the resolve() method it is even easier:

file handle tempdir /name = "c:/users/temp".

begin program python.
import spss, spssaux
file_handles = {f[0]: f[1] for f in spss.GetFileHandles()}
tempdir = file_handles["tempdir"]
alsoTempdir = spssaux.FileHandles().resolve("tempdir")
end program.

Now, in R (of course) things are not as straightforward. Is the following the best way to easily access file handles in R? (I am aware of Sys.getenv, but I am looking for something more generic):

begin program r.
fh <- spssdata.GetFileHandles()
file_handles <- sapply(fh, function(x) x[2])   # shudder
names(file_handles) <-  sapply(fh, function(x) x[1])  # shudder once more
tempdir <- file_handles["tempdir"]
end program.

spssdata.GetFileHandles.resolve("tempdir") might be an option, but it does not exist AFAIK.

Regards,
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD