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 674055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:39:49+00:00 2026-05-14T00:39:49+00:00

Is it possible, in the expr expression of the with() function, to access the

  • 0

Is it possible, in the expr expression of the with() function, to access the data argument directly? Here’s what I mean conceptually:

> print(df)
  result qid     f1     f2     f3
1     -1   1 0.0000 0.1253 0.0000
2     -1   1 0.0098 0.0000 0.0000
3      1   1 0.0000 0.0000 0.1941
4     -1   2 0.0000 0.2863 0.0948
5      1   2 0.0000 0.0000 0.0000
6      1   2 0.0000 0.7282 0.9087
> with(df, subset(.data, select=f1:f3))  # Doesn't work

Of course the above example is kind of silly, but it would be handy for things like this:

with(subset(df, f2>0), foo(qid, vars=subset(.data, select=f1:f3)))

I tried to poke around with environment() and parent.frame() etc., but didn’t come up with anything that worked.

Maybe this is really a question about eval(), since that’s how with.default() is implemented.

  • 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-05-14T00:39:50+00:00Added an answer on May 14, 2026 at 12:39 am

    Using parent.frame():

    # sample data:
    set.seed(2436502)
    dfrm <- data.frame(x1 = rnorm(100), x2 = rnorm(100), g1 = sample(letters, 100, TRUE))
    
    # how to use it:
    with(subset(dfrm, x1<0), {
        str(parent.frame(2)$data)
        "Hello!"
    })
    
    # 'data.frame':   47 obs. of  3 variables:
    #  $ x1: num  -0.836 -0.343 -0.341 -1.044 -0.665 ...
    #  $ x2: num  0.362 0.727 0.62 -0.178 -1.538 ...
    #  $ g1: Factor w/ 26 levels "a","b","c","d",..: 11 4 15 19 8 13 22 15 15 23 ...
    

    How the magic works

    Using ls() you can inspect parent.frames:

    with(subset(dfrm, x1<0), {
        print(ls())
        print(ls(parent.frame(1)))
        print(ls(parent.frame(2)))
        print(ls(parent.frame(3)))
    })
    # [1] "g1" "x1" "x2"
    # [1] "enclos" "envir"  "expr"  
    # [1] "data" "expr"
    # [1] "dfrm"
    

    As you can see:

    • parent.frame(3) is base environment (in this case),
    • parent.frame(2) is environment of subset function
    • parent.frame(1) is environment of { function (see ?Paren)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The online documentation says Hash[expr] gives an integer hash code for the expression expr.
I'm currently writing an expression parser. I've done the lexical and syntactic analysis and
I'm trying to figure out how to do a left-associative expression where recursive (not-enclosed
I've been playing around with RankNTypes recently and wonder if it is possible to
Possible Duplicate: Lock the Android device programmatically I want to lock the screen through
Possible Duplicate: Parse string into argv/argc I'm trying to write a fake shell using
Possible Duplicate: What's the difference between a temp table and table variable in SQL
Around 6 years ago, I benchmarked my own parser combinators in OCaml and found
Basically NUnit, xUnit, MbUnit, MsTest and the like have methods similar to the following:
I consider myself fairly competent in understanding and manipulating C-ish languages; it's not a

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.