[R] Returning only a file path on Windows

2009-05-22 Thread amvds
I am choosing a file like this:

#Bring up file selection box
fn-file.choose()
fp-file.path(fn,fsep='\\')

Unfortunately, the file path contains the short file name and extension as
well. I had hoped to get only the path so I could make my own long
filenames (for output graphs) by concatenation with this file path.

Of course I can split the string and assemble the components from the
returned list:

fp-strsplit(fp,'\\',fixed=TRUE)


But there must be a better way?

Thanks in advance,
Alex van der Spek

__
R-help@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.


Re: [R] Returning only a file path on Windows

2009-05-22 Thread Duncan Murdoch

On 5/22/2009 10:45 AM, am...@xs4all.nl wrote:

I am choosing a file like this:

#Bring up file selection box
fn-file.choose()
fp-file.path(fn,fsep='\\')


file.path() constructs a path from component parts, it doesn't extract 
the path from a filename.


You want dirname(fn).  You may also want to look at normalizePath, to 
convert short names to long ones, or shortPathName, for the reverse.


Duncan Murdoch



Unfortunately, the file path contains the short file name and extension as
well. I had hoped to get only the path so I could make my own long
filenames (for output graphs) by concatenation with this file path.

Of course I can split the string and assemble the components from the
returned list:

fp-strsplit(fp,'\\',fixed=TRUE)


But there must be a better way?

Thanks in advance,
Alex van der Spek

__
R-help@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.


__
R-help@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.


Re: [R] Returning only a file path on Windows

2009-05-22 Thread Uwe Ligges

Are you looking for choose.dir() ?
Or basename() and dirname()?

Uwe Ligges

am...@xs4all.nl wrote:

I am choosing a file like this:

#Bring up file selection box
fn-file.choose()
fp-file.path(fn,fsep='\\')

Unfortunately, the file path contains the short file name and extension as
well. I had hoped to get only the path so I could make my own long
filenames (for output graphs) by concatenation with this file path.

Of course I can split the string and assemble the components from the
returned list:

fp-strsplit(fp,'\\',fixed=TRUE)


But there must be a better way?

Thanks in advance,
Alex van der Spek

__
R-help@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.


__
R-help@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.