Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:11:21+00:00 2026-06-18T14:11:21+00:00

Given a vector of strings, I would like to create an expression without the

  • 0

Given a vector of strings, I would like to create an expression without the quotation marks.

# eg, I would like to go from 
c("string1", "string2")

# to...  (notice the lack of '"' marks)
quote(list(string1, string2))

I am encountering some difficulty dropping the quotation marks

input <- c("string1", "string2")
output <- paste0("quote(list(", paste(input, collapse=","), "))")

# not quite what I am looking for.     
as.expression(output)
expression("quote(list(string1,string2))")




This is for use in data.table column selection, in case relevant.

What I am looking for should be able to fit into data.table as follows:

library(data.table)
mydt <- data.table(id=1:3, string1=LETTERS[1:3], string2=letters[1:3])

result <- ????? # some.function.of(input)
> mydt[ , eval( result )]
   string1 string2
1:       A       a
2:       B       b
3:       C       c
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:11:23+00:00Added an answer on June 18, 2026 at 2:11 pm

    Here is what I’d do:

    ## Create an example of a data.table "dt" whose columns you want to index 
    ## using a character vector "xx"
    library(data.table)
    dt <- data.table(mtcars)
    xx <- c("wt", "mpg")
    
    ## Construct a call object identical to that produced by quote(list("wt", "mpg"))
    jj <- as.call(lapply(c("list", xx), as.symbol))
    
    ## Try it out
    dt[1:5,eval(jj)]
    #       wt  mpg
    # 1: 2.620 21.0
    # 2: 2.875 21.0
    # 3: 2.320 22.8
    # 4: 3.215 21.4
    # 5: 3.440 18.7
    

    When “computing on the language” like this, it’s often helpful to have a look at the structure of the object you’re trying to construct. Based on the following (and once you know about as.call() and as.symbol()), creating the desired language object becomes a piece of cake:

    x <- quote(list(wt, mpg))
    
    str(x)
    #  language list(wt, mpg)
    
    class(x)
    # [1] "call"
    
    str(as.list(x))
    # List of 3
    #  $ : symbol list
    #  $ : symbol wt
    #  $ : symbol mpg
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to pass a vector of strings from C++ to MATLAB. I
Given a multimap<A,B> M what's a neat way to create a vector<B> of all
quick question here. I'm wondering how to create a 2D vector from user input.
In my program I would like to manipulate boost::filesystem::path elements of a vector in
I would like to convert an integer [] [] to a Vector<Vector<Double>> . After
How can I access elements from myVector like i would do with arrays (
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
I have to do the following: Given a vector with random numbers, separate it
In R, given a vector casp6 <- c(0.9478638, 0.7477657, 0.9742675, 0.9008372, 0.4873001, 0.5097587, 0.6476510,
Given an STL vector, output only the duplicates in sorted order, e.g., INPUT :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.