Hi, As I can see via path.expand a filename which contains a tilde anywhere gets automatically crippled. +> path.expand("a ~ b") [1] "a /home/user b" +> path.expand("a ~ b ~") [1] "a /home/user b /home/user" I want to open a file regardless whether its name contains any character unless 0. The unix filesystem allow the creation of such files, it sould be possible to open these. How can I switch off any file crippling activity? Kind regards, Frank
>>>>> "FS" == Frank Schwidom <schwidom at gmx.net> 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
On 2019-06-05 20:32:07, Enrico Schumann wrote:> >>>>> "FS" == Frank Schwidom <schwidom at gmx.net> 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 day 10 svn rev 66115 language R version.string R version 3.1.1 (2014-07-10) nickname Sock it to Me Kind regards, Frank
On 2019-06-05 20:32:07, Enrico Schumann wrote:> >>>>> "FS" == Frank Schwidom <schwidom at gmx.net> 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
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
> On Jun 6, 2019, at 3:59 AM, 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. >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
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 <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]]