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

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem was that Moq didn't treat the Status property… May 14, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer The way I would do this is simply generate a… May 14, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer OK, well I've got it working, well sort of not… May 14, 2026 at 6:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.