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

  • SEARCH
  • Home
  • 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 8729683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:52:39+00:00 2026-06-13T08:52:39+00:00

Sorry if the question is unclear. Feel free to change it. So basically I

  • 0

Sorry if the question is unclear. Feel free to change it.

So basically I am trying to find a way so that text/character string arguments for a function don’t require quotes.

foo  = function(x, y, data){
    n1 = length(data[,x])
    n2 = length(data[,y])
    cat(n1, n1)
 }

If I use the following code

data(survey)
foo(Sex, Fold, survey)

I will get an error message. But if I use the following:

foo("Sex", "Fold", survey)

or

foo(1, 5, survey)

the function will give me what I want. So I wonder if there is any way to construct the function such that I won’t need to use quotes around the column names. Thanks!

  • 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-13T08:52:40+00:00Added an answer on June 13, 2026 at 8:52 am

    Well, this will work with the symbols:

    foo  = function(x,y, data){
        n1 <- length(eval(substitute(x),data))
        n2 <- length(eval(substitute(y),data))
        cat(n1,n2)  
    }
    

    If you wanted this to work with quoted variable names and integer indices as well, you could simply check x and y at the start with some simple if-else branching.

    But it comes with the standard warning that the eval(substitute()) idiom can be dangerous to use. (You may not always be able to anticipate how it won’t work in some cases, and you may not realize when it isn’t working.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im sorry for if the question is bit unclear. please feel free to clearup/generelize
Sorry if that question was a bit unclear. Let me try to explain. I
Sorry if my question was unclear. I got a bunch of elements and the
Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry for newbie question but is there a way to import someone else commit
Sorry for an unclear question previously; hopefully I can start again... I have this
Sorry for question title. I can not find a suitable title. I have UITableView
I'm sorry if question title was unclear, but with my cheap english, I cant
Kind of an unclear question but I'm trying to check if a username has
Sorry, I'm new to Java, so this question might be unclear. I have been

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.