[R] Open a file which name contains a tilde

Frank Schwidom @chw|dom @end|ng |rom gmx@net
Wed Jun 5 21:50:44 CEST 2019


On 2019-06-05 20:32:07, Enrico Schumann wrote:
> >>>>> "FS" == Frank Schwidom <schwidom using 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



More information about the R-help mailing list