Re: [R] define stuff to be only usable in the same file
Packaging ist still too complicated for my level i guess, can't get it to work properly, and it seems a lot of work. However apparently putting a . in front of functions will hide them, saw that in another script, don't know what its about, but it works, so who cares.. On 10.07.2012, at 17:02, Jessica Streicher wrote: On 10.07.2012, at 16:45, Jessica Streicher wrote: On 10.07.2012, at 15:24, Duncan Murdoch wrote: On 12-07-10 9:13 AM, Jessica Streicher wrote: Hello R-Help! I've looked around and have not found: A simple(short) way to hide functions and variables from the global environment. What i want is for a few of them to only be accessable from the scriptfile they're in. I probably could do fun things with environments , but that seems quite a hassle. The simplest and best way to do this is to write a package. After an hour i can say it is neither simple nor short nor will it work at all at the moment ERROR cannot change to directory 'testpack' - tried to use the build command from pretty much everywhere Forget about that, i'm stupid and can't use the tools available... You can also use local() around the code in a script, but it gets messy when you want to export more than one thing. I think local isn't quite what i imagined. Duncan Murdoch As example: I have a file that gets me stuff from the database and creates an R object from the results, plus some functions on that object. Now i want the objectrelated stuff to be global, while the functions and variables i use for accessing the database shall be hidden. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] define stuff to be only usable in the same file
On Tue, Jul 10, 2012 at 4:02 PM, Jessica Streicher j.streic...@micromata.de wrote: Forget about that, i'm stupid and can't use the tools available... Here's something I wrote specially for all you wonderful stupid people out there... https://gist.github.com/3025606 What it tries to do is to wrap all the messy business of loading functions from an R file into a separate place on your search path. You just do: tach(foo.R) and anything defined in foo.R will be usable but not visible when you do ls(). If you edit and save foo.R then just do retach() to rescan all the .R files you might have tached earlier. Stuff in your ls() environment can mask stuff attached via tach, so watch out for that. Barry [ technical note: all it does is to source the file into an environment, and attach that environment. The environment is S3-superclassed so that retach can do its business ] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] define stuff to be only usable in the same file
Thanks Barry, that helped a lot, modified it a bit and it does pretty much what i wanted. On 11.07.2012, at 15:08, Barry Rowlingson wrote: On Tue, Jul 10, 2012 at 4:02 PM, Jessica Streicher j.streic...@micromata.de wrote: Forget about that, i'm stupid and can't use the tools available... Here's something I wrote specially for all you wonderful stupid people out there... https://gist.github.com/3025606 What it tries to do is to wrap all the messy business of loading functions from an R file into a separate place on your search path. You just do: tach(foo.R) and anything defined in foo.R will be usable but not visible when you do ls(). If you edit and save foo.R then just do retach() to rescan all the .R files you might have tached earlier. Stuff in your ls() environment can mask stuff attached via tach, so watch out for that. Barry [ technical note: all it does is to source the file into an environment, and attach that environment. The environment is S3-superclassed so that retach can do its business ] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] define stuff to be only usable in the same file
Hello R-Help! I've looked around and have not found: A simple(short) way to hide functions and variables from the global environment. What i want is for a few of them to only be accessable from the scriptfile they're in. I probably could do fun things with environments , but that seems quite a hassle. As example: I have a file that gets me stuff from the database and creates an R object from the results, plus some functions on that object. Now i want the objectrelated stuff to be global, while the functions and variables i use for accessing the database shall be hidden. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] define stuff to be only usable in the same file
On 12-07-10 9:13 AM, Jessica Streicher wrote: Hello R-Help! I've looked around and have not found: A simple(short) way to hide functions and variables from the global environment. What i want is for a few of them to only be accessable from the scriptfile they're in. I probably could do fun things with environments , but that seems quite a hassle. The simplest and best way to do this is to write a package. You can also use local() around the code in a script, but it gets messy when you want to export more than one thing. Duncan Murdoch As example: I have a file that gets me stuff from the database and creates an R object from the results, plus some functions on that object. Now i want the objectrelated stuff to be global, while the functions and variables i use for accessing the database shall be hidden. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] define stuff to be only usable in the same file
On 10.07.2012, at 15:24, Duncan Murdoch wrote: On 12-07-10 9:13 AM, Jessica Streicher wrote: Hello R-Help! I've looked around and have not found: A simple(short) way to hide functions and variables from the global environment. What i want is for a few of them to only be accessable from the scriptfile they're in. I probably could do fun things with environments , but that seems quite a hassle. The simplest and best way to do this is to write a package. After an hour i can say it is neither simple nor short nor will it work at all at the moment ERROR cannot change to directory 'testpack' - tried to use the build command from pretty much everywhere You can also use local() around the code in a script, but it gets messy when you want to export more than one thing. I think local isn't quite what i imagined. Duncan Murdoch As example: I have a file that gets me stuff from the database and creates an R object from the results, plus some functions on that object. Now i want the objectrelated stuff to be global, while the functions and variables i use for accessing the database shall be hidden. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] define stuff to be only usable in the same file
On 10.07.2012, at 16:45, Jessica Streicher wrote: On 10.07.2012, at 15:24, Duncan Murdoch wrote: On 12-07-10 9:13 AM, Jessica Streicher wrote: Hello R-Help! I've looked around and have not found: A simple(short) way to hide functions and variables from the global environment. What i want is for a few of them to only be accessable from the scriptfile they're in. I probably could do fun things with environments , but that seems quite a hassle. The simplest and best way to do this is to write a package. After an hour i can say it is neither simple nor short nor will it work at all at the moment ERROR cannot change to directory 'testpack' - tried to use the build command from pretty much everywhere Forget about that, i'm stupid and can't use the tools available... You can also use local() around the code in a script, but it gets messy when you want to export more than one thing. I think local isn't quite what i imagined. Duncan Murdoch As example: I have a file that gets me stuff from the database and creates an R object from the results, plus some functions on that object. Now i want the objectrelated stuff to be global, while the functions and variables i use for accessing the database shall be hidden. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.