Re: [R] Open a file which name contains a tilde

2019-06-14 Thread Frank Schwidom
Hi John,

First, the unix and linux filesystem allows the use of any nonzero character in 
its filesystem filenames and the c functions open / fopen, symlink. rename, 
chdir and so on  don't care about any tilde. If the open systemcall gets a file 
which begins with a tilde then it will try to open this filename without any 
preceding modification.

So the tilde expansion is not really a unix idiom. It is rather an idiom of its 
unix shells like bash. But beware, the bash treats the tilde as home path not 
in all cases.

Inside of quotes the tilde keeps unaltered. So bedides any cenvenience 
functionality which can lead to failing code the bash has a very clean way to 
access files in a unique way.

And here is the problem wirh R.

The R shell has no quoting mechanism for this use case. It provides the tilde 
expansion after a string has been defined. In the bash it is the opposite. 
First the string gets defined ( for instance ~"/abc.txt" would expand to 
"/home/user/abc.txt" or "~/abc.txt" keeps "~/abc.txt" and that means a 
directory named '~' with a directory entry named 'abc.txt' inside of it) and 
after it is defined it keeps consistent and can be passed to every function.

Actually R has already a clean string datatype. But by the transition to 
filesystem operations the expansion takes place. In my opinion at the wrong 
place. And additionally there exists no quoting mechanism which allows to keep 
tildes unaltered.  It would be better to clear distinguish between a string 
which is passed to the filesystem calls and some convenience expansion 
mechanisms.

But it is like it is. For my need I created a solution which takes strings 
unaltered and so I can fulfil my work.

And for whom who is interested in it, can take a look:

https://github.com/schwidom/simplefs

Suggestions are welcome.

Kind regards
Frank Schwidom



On 2019-06-12 12:50:12, John via R-help wrote:
> On Wed, 5 Jun 2019 18:07:15 +0200
> Frank Schwidom  wrote:
>
> In reading file names, names with spaces require escaping of the
> spaces, and you are using not only a tilde but the space as spell.  The
> tilde is conventionally read as wild card representing the leading
> portion of the file address, which is what you see here:
>
> The long standing convention in unix and linux is that a tilde is
> shorthand for your home directory, just as "./" is the local directory
> and "../" is one step back up the directory tree. The output of
> path.expand() varies in how your string is constructed:
>
> 1. > path.expand("ab")
>[1] "ab"
> 2. > path.expand("a b")
>[1] "a b"
> 3. > path.expand("a ~b")
>[1] "a ~b"
> 4. > path.expand("a ~ b")
>[1] "a /home/john b"
> 5. > path.expand("a ~/b")
>[1] "a /home/john/b"
> 6. > path.expand("~/a  b")
>[1] "/home/john/a  b"
>
> Notice that the spaces have an effect on how the tilde is parsed in
> the string.  The next to last case sees a string with three elements:
> "a", the local path, and "b".  The last expands the tilde as the "path"
> to a hypothetical file "b" in the home directory. In the sixth case the
> same behaviour occurs.
>
> If you read the help for path.expand(), the routine expects
> "leading" tildes, which explains the free floating "path in the fourth
> example.  In the third example, where the forward slash is omitted, the
> routine simply treats the tilde as part of a string.
>
> Also note this at http://www.linfo.org/file_name.html:
>
> "...file names only use alphanumeric characters (mostly lower case),
> underscores, hyphens and periods. Other characters, such as dollar
> signs, percentage signs and brackets, have special meanings to the
> shell and can be distracting to work with. File names should never
> begin with a hyphen."
>
> The probable "bug" is that none of the programmers imagined that anyone
> would use special characters within file names, "legal" or not, (just
> not done, don't y' know). In any case the simple solution, if you
> really, really need a tilde in a filename, is to avoid setting it off in
> spaces, or any other character that could mislead a routine into
> treating it conventionally as shorthand for you home directory.
>
> JWDougherty
>
> __
> R-help@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.
>

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


Re: [R] Open a file which name contains a tilde

2019-06-12 Thread John via R-help
On Wed, 5 Jun 2019 18:07:15 +0200
Frank Schwidom  wrote:

In reading file names, names with spaces require escaping of the
spaces, and you are using not only a tilde but the space as spell.  The
tilde is conventionally read as wild card representing the leading
portion of the file address, which is what you see here:

The long standing convention in unix and linux is that a tilde is
shorthand for your home directory, just as "./" is the local directory
and "../" is one step back up the directory tree. The output of
path.expand() varies in how your string is constructed:

1. > path.expand("ab")
   [1] "ab"
2. > path.expand("a b")
   [1] "a b"
3. > path.expand("a ~b")
   [1] "a ~b"
4. > path.expand("a ~ b")
   [1] "a /home/john b"
5. > path.expand("a ~/b")
   [1] "a /home/john/b"
6. > path.expand("~/a  b")
   [1] "/home/john/a  b"

Notice that the spaces have an effect on how the tilde is parsed in
the string.  The next to last case sees a string with three elements:
"a", the local path, and "b".  The last expands the tilde as the "path"
to a hypothetical file "b" in the home directory. In the sixth case the
same behaviour occurs.  

If you read the help for path.expand(), the routine expects
"leading" tildes, which explains the free floating "path in the fourth
example.  In the third example, where the forward slash is omitted, the
routine simply treats the tilde as part of a string. 

Also note this at http://www.linfo.org/file_name.html:

"...file names only use alphanumeric characters (mostly lower case),
underscores, hyphens and periods. Other characters, such as dollar
signs, percentage signs and brackets, have special meanings to the
shell and can be distracting to work with. File names should never
begin with a hyphen."

The probable "bug" is that none of the programmers imagined that anyone
would use special characters within file names, "legal" or not, (just
not done, don't y' know). In any case the simple solution, if you
really, really need a tilde in a filename, is to avoid setting it off in
spaces, or any other character that could mislead a routine into
treating it conventionally as shorthand for you home directory.  

JWDougherty

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


Re: [R] Open a file which name contains a tilde

2019-06-10 Thread Frank Schwidom
Hi,

to get rid of any possible filename modification I started a little project to 
cover my usecase:

https://github.com/schwidom/simplefs

This is my first R package, suggestions and a review are welcome.

Thanks in advance
Frank Schwidom

On 2019-06-07 09:04:06, Richard O'Keefe wrote:
>How can expanding tildes anywhere but the beginning of a file name NOT be
>considered a bug?
>On Thu, 6 Jun 2019 at 23:04, Ivan Krylov <[1]krylov.r...@gmail.com> wrote:
>
>  On Wed, 5 Jun 2019 18:07:15 +0200
>  Frank Schwidom <[2]schwi...@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]
>  
> [3]https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
>
>  [2]
>  
> [4]https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
>
>  [3]
>  
> [5]https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147
>
>  [4]
>  
> [6]https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494
>
>  [5]
>  
> [7]https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
>
>  __
>  [8]R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  [9]https://stat.ethz.ch/mailman/listinfo/r-help
>  PLEASE do read the posting guide
>  [10]http://www.R-project.org/posting-guide.html
>  and provide commented, minimal, self-contained, reproducible code.
>
> References
>
>Visible links
>1. mailto:krylov.r...@gmail.com
>2. mailto:schwi...@gmx.net
>3. 
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
>4. 
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
>5. 
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147
>6. 
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494
>7. https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
>8. mailto:R-help@r-project.org
>9. https://stat.ethz.ch/mailman/listinfo/r-help
>   10. http://www.r-project.org/posting-guide.html

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


Re: [R] Open a file which name contains a tilde

2019-06-08 Thread Rui Barradas

Hello,

R 3.6.0 on Ubuntu 19.04.
Since no one mentioned it, notice that the tilde in the middle of a 
string needs to be surrounded by spaces to be expanded.


The first code line works as expected, only the second is wrong (buggy).

path.expand('a~b')
#[1] "a~b"
path.expand('a ~ b')
#[1] "a /home/rui b"


Rui Barradas

Às 04:27 de 08/06/19, Richard O'Keefe escreveu:

?path.expand
 Expand a path name, for example by replacing a leading tilde by
 the user's home directory (if defined on that platform).

*A* path name.  The argument is a character vector.
If multiple path names are passed, they are passed

 On most builds of R *A LEADING* "~user" will be replaced...

Nothing is said in the R documentation about *multiple* or
*non-leading* tildes being replaced.

The actual behaviour is inconsistent with the documentation.
SOMETHING is a bug.

It's not clear to me why this is in any way dependent on
readline.  I've implemented tilde expansion several times
and always without readline.
It sounds as though R might be calling tilde_expand()
when it *should*, to be consistent with the documentation,
be calling tilde_expand_word().



as separate elements of the character vector.



On Sat, 8 Jun 2019 at 04:10, Berry, Charles  wrote:





On Jun 6, 2019, at 2:04 PM, Richard O'Keefe  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@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  wrote:


On Wed, 5 Jun 2019 18:07:15 +0200
Frank Schwidom  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/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807


[2]



https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915


[3]



https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147


[4]



https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494


[5]


https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187


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







[[alternative HTML version deleted]]

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



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


Re: [R] Open a file which name contains a tilde

2019-06-07 Thread Richard O'Keefe
?path.expand
Expand a path name, for example by replacing a leading tilde by
the user's home directory (if defined on that platform).

*A* path name.  The argument is a character vector.
If multiple path names are passed, they are passed

On most builds of R *A LEADING* "~user" will be replaced...

Nothing is said in the R documentation about *multiple* or
*non-leading* tildes being replaced.

The actual behaviour is inconsistent with the documentation.
SOMETHING is a bug.

It's not clear to me why this is in any way dependent on
readline.  I've implemented tilde expansion several times
and always without readline.
It sounds as though R might be calling tilde_expand()
when it *should*, to be consistent with the documentation,
be calling tilde_expand_word().



as separate elements of the character vector.



On Sat, 8 Jun 2019 at 04:10, Berry, Charles  wrote:

>
>
> > On Jun 6, 2019, at 2:04 PM, Richard O'Keefe  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@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  wrote:
> >
> >> On Wed, 5 Jun 2019 18:07:15 +0200
> >> Frank Schwidom  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/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
> >>
> >> [2]
> >>
> >>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
> >>
> >> [3]
> >>
> >>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147
> >>
> >> [4]
> >>
> >>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494
> >>
> >> [5]
> >>
> https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
> >>
> >> __
> >> R-help@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]]
> >
>
>
>

[[alternative HTML version deleted]]

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


Re: [R] Open a file which name contains a tilde

2019-06-07 Thread Berry, Charles



> On Jun 6, 2019, at 2:04 PM, Richard O'Keefe  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@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  wrote:
> 
>> On Wed, 5 Jun 2019 18:07:15 +0200
>> Frank Schwidom  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/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
>> 
>> [2]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
>> 
>> [3]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147
>> 
>> [4]
>> 
>> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494
>> 
>> [5]
>> https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
>> 
>> __
>> R-help@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]]
> 

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


Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Duncan Murdoch

On 06/06/2019 5:04 p.m., Richard O'Keefe wrote:

How can expanding tildes anywhere but the beginning of a file name NOT be
considered a bug?


It looks like a bug in R, but not necessarily a bug in libreadline:  we 
may just be using tilde_expand improperly.


Duncan Murdoch




On Thu, 6 Jun 2019 at 23:04, Ivan Krylov  wrote:


On Wed, 5 Jun 2019 18:07:15 +0200
Frank Schwidom  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/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807

[2]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915

[3]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147

[4]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494

[5]
https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187

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

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



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


Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Richard O'Keefe
How can expanding tildes anywhere but the beginning of a file name NOT be
considered a bug?


On Thu, 6 Jun 2019 at 23:04, Ivan Krylov  wrote:

> On Wed, 5 Jun 2019 18:07:15 +0200
> Frank Schwidom  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/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
>
> [2]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
>
> [3]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147
>
> [4]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494
>
> [5]
> https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
>
> __
> R-help@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]]

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


Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Berry, Charles



> On Jun 6, 2019, at 3:59 AM, Ivan Krylov  wrote:
> 
> On Wed, 5 Jun 2019 18:07:15 +0200
> Frank Schwidom  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.
> 

FWIW, the tilde does not always trigger this behavior. 

It seems that the tilde needs to be first in the string or preceded by 
whitespace and succeeded by whitespace or a path separator so the result looks 
like a path. 

> path.expand("~/abc/~/def")
[1] "/Users/cberry/abc/~/def"
> 

> path.expand("~/abc/ ~/def")
[1] "/Users/cberry/abc/ /Users/cberry/def"

> path.expand("~/abc/ ~tilde~/def")
[1] "/Users/cberry/abc/ ~tilde~/def"
> 
> path.expand("~/abc/ ~tilde ~/def")
[1] "/Users/cberry/abc/ ~tilde /Users/cberry/def"

An inelegant workaround could be built by adding escapes to the initial path 
and stripping them from the result.

Perhaps, the intent (in GNU deadline) was to allow a string with multiple paths 
separated by whitespace to be processed.

Maybe this is seen as a feature in GNU readline even though it is not helpful 
here.

HTH,

Chuck

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


Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Ivan Krylov
On Wed, 5 Jun 2019 18:07:15 +0200
Frank Schwidom  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/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807

[2]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915

[3]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147

[4]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494

[5]
https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187

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


Re: [R] Open a file which name contains a tilde

2019-06-05 Thread Enrico Schumann



Quoting Frank Schwidom :


On 2019-06-05 20:32:07, Enrico Schumann wrote:

> "FS" == Frank Schwidom  writes:

FS> Hi,
FS> As I can see via path.expand a filename which contains a 
 FS> tilde anywhere gets automatically crippled.


FS> +> path.expand("a ~ b")
FS> [1] "a /home/user b"

FS> +> path.expand("a ~ b ~")
FS> [1] "a /home/user b /home/user"

FS> I want to open a file regardless whether its name contains   
   FS> any character unless 0.


FS> The unix filesystem allow the creation of such files, it 
 FS> sould be possible to open these.


FS> How can I switch off any file crippling activity?

FS> Kind regards,
FS> Frank

Do you need 'path.expand'? For example,

readLines("~/Desktop/a ~ b")

reads just fine the content of a file named
'a ~ b' on my desktop.



Appendix:

I found out in the meantime that I can use 'R --no-readline' but I  
want to use readline and I found no possible readline configuration  
/etc/inputrc).


And maybe it works as Rscript.

But that should be more consistent because it is in fact very basic.

Kind regards,
Frank


You're right. I ran the example from Emacs/ESS.
There it worked, but only because ESS uses '--no-readline'
as a default (i.e. 'ess-R-readline' is set to nil).
With readline enabled, it fails (with R 3.6.0).


--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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


Re: [R] Open a file which name contains a tilde

2019-06-05 Thread Frank Schwidom
On 2019-06-05 20:32:07, Enrico Schumann wrote:
> > "FS" == Frank Schwidom  writes:
>
> FS> Hi,
> FS> As I can see via path.expand a filename which contains a tilde 
> anywhere gets automatically crippled.
>
> FS> +> path.expand("a ~ b")
> FS> [1] "a /home/user b"
>
> FS> +> path.expand("a ~ b ~")
> FS> [1] "a /home/user b /home/user"
>
> FS> I want to open a file regardless whether its name contains any 
> character unless 0.
>
> FS> The unix filesystem allow the creation of such files, it sould be 
> possible to open these.
>
> FS> How can I switch off any file crippling activity?
>
> FS> Kind regards,
> FS> Frank
>
> Do you need 'path.expand'? For example,
>
> readLines("~/Desktop/a ~ b")
>
> reads just fine the content of a file named
> 'a ~ b' on my desktop.
>
>
> --
> Enrico Schumann
> Lucerne, Switzerland
> http://enricoschumann.net
>

Appendix:

I found out in the meantime that I can use 'R --no-readline' but I want to use 
readline and I found no possible readline configuration /etc/inputrc).

And maybe it works as Rscript.

But that should be more consistent because it is in fact very basic.

Kind regards,
Frank

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


Re: [R] Open a file which name contains a tilde

2019-06-05 Thread Frank Schwidom
On 2019-06-05 20:32:07, Enrico Schumann wrote:
> > "FS" == Frank Schwidom  writes:
>
> FS> Hi,
> FS> As I can see via path.expand a filename which contains a tilde 
> anywhere gets automatically crippled.
>
> FS> +> path.expand("a ~ b")
> FS> [1] "a /home/user b"
>
> FS> +> path.expand("a ~ b ~")
> FS> [1] "a /home/user b /home/user"
>
> FS> I want to open a file regardless whether its name contains any 
> character unless 0.
>
> FS> The unix filesystem allow the creation of such files, it sould be 
> possible to open these.
>
> FS> How can I switch off any file crippling activity?
>
> FS> Kind regards,
> FS> Frank
>
> Do you need 'path.expand'? For example,
>
> readLines("~/Desktop/a ~ b")
>
> reads just fine the content of a file named
> 'a ~ b' on my desktop.
>
>
> --
> Enrico Schumann
> Lucerne, Switzerland
> http://enricoschumann.net
>

Thanks for yor answer.

$ echo 123 > ~/'a ~ b'.txt

ls ~/'a ~ b'.txt

/home/user/a ~ b.txt

+> readLines("~/a ~ b.txt")
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/home/user/a /home/user b.txt': No such file or directory

+> version
   _
platform   x86_64-pc-linux-gnu
arch   x86_64
os linux-gnu
system x86_64, linux-gnu
status
major  3
minor  1.1
year   2014
month  07
day10
svn rev66115
language   R
version.string R version 3.1.1 (2014-07-10)
nickname   Sock it to Me

Kind regards,
Frank

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


Re: [R] Open a file which name contains a tilde

2019-06-05 Thread Enrico Schumann
> "FS" == Frank Schwidom  writes:

FS> Hi,
FS> As I can see via path.expand a filename which contains a tilde anywhere 
gets automatically crippled.

FS> +> path.expand("a ~ b")
FS> [1] "a /home/user b"

FS> +> path.expand("a ~ b ~")
FS> [1] "a /home/user b /home/user"

FS> I want to open a file regardless whether its name contains any 
character unless 0.

FS> The unix filesystem allow the creation of such files, it sould be 
possible to open these.

FS> How can I switch off any file crippling activity?

FS> Kind regards,
FS> Frank

Do you need 'path.expand'? For example,

readLines("~/Desktop/a ~ b")

reads just fine the content of a file named
'a ~ b' on my desktop.


-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

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