Assign with Paste Problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Assign with Paste Problem

Sparks, John James
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"
>

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Assign with Paste Problem

baptiste auguie-5
Hi,

You probably need ?get, though you might want to read this first,

library(fortunes)
fortune(236)

HtH,

baptiste


On 13 April 2011 13:04, Sparks, John James <[hidden email]> wrote:

> 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"
>>
>
> ______________________________________________
> [hidden email] mailing list
> 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.
>

______________________________________________
[hidden email] mailing list
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.