[R] How to join path with arguments

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Feb 19 14:16:21 CET 2008


Please just use file.path(inputdir, filename).

Apart from being less error-prone, in R 2.7.0 it will be internal and so 
faster (and in case you wonder how paste could be too slow, it was in some 
of the package installation/checking computations).

On Tue, 19 Feb 2008, Henrique Dallazuanna wrote:

> Ops,
> paste(inputdir, filename, sep="") should be paste(inputdir, filename, sep="/")
>
> On 19/02/2008, Henrique Dallazuanna <wwwhsd at gmail.com> wrote:
>> Try this:
>>
>> name1 <- 'sample-plot'
>> filename <- sprintf("%s.png", name1)
>> inputdir <- '/path/to/dir'
>> paste(inputdir, filename, sep="")
>>
>>
>> On 19/02/2008, Hyunchul Kim <sundol313 at naver.com> wrote:
>>> Hi, all
>>>
>>> How to format and join strings ?
>>> For example, like following short python examples.
>>>
>>> *********
>>> name1 = 'sample-plot'
>>> filename = '%s.png' % name1
>>>
>>> inputdir = '/path/to/dir'
>>> os.path.join(inputdir, filename)
>>>
>>> **********
>>>
>>> Best,
>>> Hyunchul Kim
>>>
>>>         [[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.
>>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list