From murdoch@dunc@n @end|ng |rom gm@||@com  Sun May  1 21:51:20 2022
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Sun, 1 May 2022 15:51:20 -0400
Subject: [Rd] "with" doesn't work with names with blanks
In-Reply-To: <a70b7e3c-8975-dd83-705b-488945bb1af0@prodsyse.com>
References: <a70b7e3c-8975-dd83-705b-488945bb1af0@prodsyse.com>
Message-ID: <44e04e08-a17f-5b34-092d-5fb172dcffb1@gmail.com>

On 01/05/2022 3:41 p.m., Spencer Graves wrote:
> Hello, All:
> 
> 
> 	  Column names in a data.frame are not supposed to have trailing
> blanks.  However, a CRAN package created one, which threw an error with
> "with".  Consider the following example:
> 
> 
>   > (tst <- data.frame(1))
>     X1
> 1  1
>   > names(tst) <- 'x '
>   > tst$x
> [1] 1
>   > with(txt, x)
> Error in with(txt, x) : object 'txt' not found
> 
> 
> 	  I think it's interesting that "tst$x" works, but "with(txt, x)".
> 
> 
> 	  Comments?

tst$x works because of partial name matching.  (That leniency is one of 
the reasons for advice to avoid using $ in programs.)  It would be chaos 
if with() used partial name matching.

You can use

with(txt, `x `)

to include the space in the name.

Duncan Murdoch

> 
> 
> 	  It's not a major problem, though it took me a while to diagnose.  (I
> reported it to the maintainer of the package that returned a data.frame
> with names with trailing blanks.)
> 
> 
> 	  Thanks, for all your work in maintaining and upgrading R -- and in
> responding to emails from this list.
> 
> 
> 	  Spencer Graves
> 
> 
>   > sessionInfo()
> R version 4.2.0 (2022-04-22)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Big Sur 11.6.5
> 
> Matrix products: default
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> loaded via a namespace (and not attached):
> [1] compiler_4.2.0 tools_4.2.0
>   >
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] "with" doesn't work with names with blanks
Duncan Murdoch