[R] Assign with Paste Problem

Sparks, John James jspark4 at uic.edu
Wed Apr 13 03:04:12 CEST 2011


Dear R Helpers,

I am trying to change the name of an object using the assign function. 
When I use paste on the new object but not the old, everything is fine:
The new object is a direct copy of the old object.  When I use a paste for
both the new and the old object, however, the new object is simply the
character representation of the old object name, not the old object
itself.

The example below uses quantmod, but you don't need that to see the nature
of the problem.

How can I get the new object to be a complete copy of the old object when
I use paste in both sides of the assign?

Your help would be most appreciated.
--John Sparks

> #Careful!  Removes everything in working directory!
> rm(list = ls())
>
> ticker<-"F"
>
> require(quantmod)
>
> getFin(paste("NYSE:",ticker,sep=""))
[1] "NYSE.F.f"
> NYSE.F.f
Financial Statement for NYSE:F
Retrieved from google at 2011-04-12 20:03:20
Use "viewFinancials" or "viewFin" to view
>
> F.f<-NYSE.F.f
> F.f
Financial Statement for NYSE:F
Retrieved from google at 2011-04-12 20:03:20
Use "viewFinancials" or "viewFin" to view
>
> rm(F.f)
>
> assign(paste(ticker,".f",sep=""),NYSE.F.f)
> F.f
Financial Statement for NYSE:F
Retrieved from google at 2011-04-12 20:03:20
Use "viewFinancials" or "viewFin" to view
>
> rm(F.f)
>
> assign(paste(ticker,".f",sep=""),paste("NYSE.",ticker,".f",sep=""))
> F.f
[1] "NYSE.F.f"
>



More information about the R-help mailing list