Skip to content

How to use a text in an object of class character position to create a vector with the text as name

4 messages · benji, Sarah Goslee, R. Michael Weylandt

#
Hello,
[1] "data.frame"
[1] Experiment name : CONTROL DB AD_1
[1] Experiment name : CONTROL DB AD_1
[1] "character"

now i want to create an object (vector) with the name "Experiment name :
CONTROL DB AD_1" , or even better if possible CONTROL DB AD_1

Thank you

--
View this message in context: http://r.789695.n4.nabble.com/How-to-use-a-text-in-an-object-of-class-character-position-to-create-a-vector-with-the-text-as-name-tp4636755.html
Sent from the R help mailing list archive at Nabble.com.
#
In general, you use assign() to do that, but having object names
containing spaces should be avoided.
[1] "Experiment name : CONTROL DB AD_1"
[1] "CONTROL DB AD_1"
[1] "CONTROL DB AD_1" "mytext"
[1] "CONTROL DB AD_1"
Error: unexpected symbol in "CONTROL DB"

Since you can't access your object by typing its name at the R prompt,
either with or without quotes, you've kind of got a problem. You could
use get(), but at that point why not just name your object something
that follows the R naming conventions?

Sarah
On Tue, Jul 17, 2012 at 11:08 AM, benji <benlucas at illinois.edu> wrote:

  
    
#
On Tue, Jul 17, 2012 at 10:55 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
I know Sarah knows this, but just for archive completeness: backticks.

`cat or dog` <- 3

cat or dog # Error

`cat or dog` # 3

Of course, this allows such insanity as

`4` <- 15

which is somewhat peculiar.

I still second the advice to use legal R names and uses underscores
where spaces might be desired.

raw_data <- 3

etc.

Best,
Michael
#
On Tue, Jul 17, 2012 at 2:23 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
I knew I was missing something.
So true.

And for convenience:
[1] "CONTROL_DB_AD_1"