Remove quotes from a character vector in R

Just try noquote(a)

noquote("a")

[1] a


You are confusing quantmod's 'symbol' (a term relating to a code for some financial thingamuwot) with R's 'symbol', which is a 'type' in R.

You've said:

I have a character vector of stock symbols that I pass to quantmod::getSymbols() and the function returns the symbol to the environment without the quotes

Well almost. What it does is create objects with those names in the specified environment. What I think you want to do is to get things out of an environment by name. And for that you need 'get'. Here's how, example code, working in the default environment:

getSymbols('F',src='yahoo',return.class='ts') [1] "F"

so you have a vector of characters of the things you want:

> z="F"
> z
[1] "F"

and then the magic:

> summary(get(z))
     F.Open           F.High           F.Low           F.Close      
 Min.   : 1.310   Min.   : 1.550   Min.   : 1.010   Min.   : 1.260  
 1st Qu.: 5.895   1st Qu.: 6.020   1st Qu.: 5.705   1st Qu.: 5.885  
 Median : 7.950   Median : 8.030   Median : 7.800   Median : 7.920  
 Mean   : 8.358   Mean   : 8.495   Mean   : 8.178   Mean   : 8.332  
 3rd Qu.:11.210   3rd Qu.:11.400   3rd Qu.:11.000   3rd Qu.:11.180  
 Max.   :18.810   Max.   :18.970   Max.   :18.610   Max.   :18.790  

and if you don't believe me:

> identical(F,get(z))
[1] TRUE

as.name(char[1]) will work, although I'm not sure why you'd ever really want to do this -- the quotes won't get carried over in a paste for example:

> paste("I am counting to", char[1], char[2], char[3])
[1] "I am counting to one two three"

There are no quotes in the return value, only in the default output from print() when you display the value. Try

> print(char[1], quote=FALSE)
[1] one

or

> cat(char[1], "\n")
one

to see the value without quotes.

Tags:

Quotes

R