From ccberry @end|ng |rom uc@d@edu  Fri Jun  7 18:08:28 2019
From: ccberry @end|ng |rom uc@d@edu (Berry, Charles)
Date: Fri, 7 Jun 2019 16:08:28 +0000
Subject: [Rd] [R] Open a file which name contains a tilde
In-Reply-To: <CABcYAdLgLrBwNW4A4EgYx0RwD9zjCo4Mpe7S05SeohoNmMQSGg__2324.26375603012$1559899589$gmane$org@mail.gmail.com>
References: <20190605160714.GA24635@debian64>
 <20190606135957.0be4db10@trisector>
 <CABcYAdLgLrBwNW4A4EgYx0RwD9zjCo4Mpe7S05SeohoNmMQSGg__2324.26375603012$1559899589$gmane$org@mail.gmail.com>
Message-ID: <4BCEF16D-A9B7-460B-9E47-91B8A7B5DAB2@ucsd.edu>



> On Jun 6, 2019, at 2:04 PM, Richard O'Keefe <raoknz at gmail.com> wrote:
> 
> How can expanding tildes anywhere but the beginning of a file name NOT be
> considered a bug?
> 
> 

I think that that IS what libreadline is doing if one allows a whitespace separated list of file names.

As reported in R-help, 

	https://www.mail-archive.com/r-help at r-project.org/msg254116.html

path.expand seems to expand tildes beginning whitespace separated strings that could be filenames, but not other tildes.

Thus,

> path.expand("~/.newsrc ~/.R/*")  # expands both tildes
[1] "/Users/cberry/.newsrc /Users/cberry/.R/*"
> path.expand("~/.newsrc~/.R/*")   # expands only the first
[1] "/Users/cberry/.newsrc~/.R/*"
> 

This could be a feature if what one wanted was to pass the result to a system command that will process multiple file arguments, e.g. 

> system(paste( "wc", path.expand("~/.newsrc ~/.R/*"))) # run wc on some files

I doubt that this was intended by R-core, but perhaps the readline devs had this in mind. 

Chuck


> On Thu, 6 Jun 2019 at 23:04, Ivan Krylov <krylov.r00t at gmail.com> wrote:
> 
>> On Wed, 5 Jun 2019 18:07:15 +0200
>> Frank Schwidom <schwidom at gmx.net> wrote:
>> 
>>> +> path.expand("a ~ b")
>>> [1] "a /home/user b"
>> 
>>> How can I switch off any file crippling activity?
>> 
>> It doesn't seem to be possible if readline is enabled and works
>> correctly.
>> 
>> Calls to path.expand [1] end up [2] in R_ExpandFileName [3], which
>> calls R_ExpandFileName_readline [4], which uses libreadline function
>> tilde_expand [5]. tilde_expand seems to be designed to expand '~'
>> anywhere in the string it is handed, i.e. operate on whole command
>> lines, not file paths.
>> 
>> I am taking the liberty of Cc-ing R-devel in case this can be
>> considered a bug.
>> 
>> --
>> Best regards,
>> Ivan
>> 
>> [1]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e333348b81180a0e2c6f2f/src/main/names.c#L807
>> 
>> [2]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e333348b81180a0e2c6f2f/src/main/platform.c#L1915
>> 
>> [3]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e333348b81180a0e2c6f2f/src/unix/sys-unix.c#L147
>> 
>> [4]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e333348b81180a0e2c6f2f/src/unix/sys-std.c#L494
>> 
>> [5]
>> https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>> 
> 
> 	[[alternative HTML version deleted]]
> 



[Rd] [R] Open a file which name contains a tilde
Berry, Charles