Skip to content

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Feb 19, 2015

Hello,

This is a small change to have a more useful way of creating environments with Rcpp.

@eddelbuettel
Copy link
Member

Thanks for the contribution. Do you have a usage example? And/or test case we can add to the unit tests?

@lionel-
Copy link
Contributor Author

lionel- commented Feb 19, 2015

For example you can capture the calling environment to your cpp function from its R wrapper with parent.frame(). Then you create a new environment (call it my_env) that has the calling env as parent. You can put several things in there, knowing that it won't have side effects, and then evaluate some R code with Rf_eval() in this environment. Variable lookup will first take place in my_env, then in the calling env, then its parent and so on.

I could add a test that checks that the parent is the correct one if you want.

@eddelbuettel
Copy link
Member

Yes, I would really appreciate a few (simple) tests as part of the PR.

@lionel-
Copy link
Contributor Author

lionel- commented Feb 19, 2015

Here you go.

@lionel-
Copy link
Contributor Author

lionel- commented Feb 19, 2015

wait a minute, I made a mistake in there

why did the test not fail? :/

@lionel-
Copy link
Contributor Author

lionel- commented Feb 19, 2015

ok, I should have used checkIdentical()

should be good now

@eddelbuettel
Copy link
Member

Looks good. Odd indeed that checkEquals() failed there.

eddelbuettel added a commit that referenced this pull request Feb 19, 2015
Allow new_env() to create an environment with a specified parent
@eddelbuettel eddelbuettel merged commit 9af0650 into RcppCore:master Feb 19, 2015
@lionel- lionel- deleted the new_env branch February 19, 2015 22:14
@lionel-
Copy link
Contributor Author

lionel- commented Feb 19, 2015

Thanks for your quick review!

jmp75 pushed a commit to jmp75/Rcpp that referenced this pull request Mar 16, 2015
Allow new_env() to create an environment with a specified parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants