access data inside package

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

access data inside package

baptiste auguie
Dear all,

Happy new year!

I posted a very similar question a few days ago, but probably too  
cluttered. Here is a tidy, minimal version:

I want to make a package, with a data.frame d and a function f given  
below. Now, the function f needs to use the data.frame d. I could  
(and that's what I've done temporarily) make a local duplicate of  
this data.frame in the function definition, but it seems silly.

I've tried "attach()", "data()", but both fail when running R CMD  
check with the error

> * checking R code for possible problems ... NOTE
> f: no visible binding for global variable 'd'

Here is the minimal package skeleton:

> d <- data.frame(a=1)
>
> f <- function(x)
> {
> data("d")
> x+d$a
> }
>
> package.skeleton(list=c("f","d"), name="mypkg")


What would be a sensible way to refer to this data inside the package?

Best regards,

baptiste

_____________________________

Baptiste Auguié

Physics Department
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
http://projects.ex.ac.uk/atto

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Uwe Ligges


baptiste Auguié wrote:

> Dear all,
>
> Happy new year!
>
> I posted a very similar question a few days ago, but probably too  
> cluttered. Here is a tidy, minimal version:
>
> I want to make a package, with a data.frame d and a function f given  
> below. Now, the function f needs to use the data.frame d. I could  
> (and that's what I've done temporarily) make a local duplicate of  
> this data.frame in the function definition, but it seems silly.
>
> I've tried "attach()", "data()", but both fail when running R CMD  
> check with the error
>
>> * checking R code for possible problems ... NOTE
>> f: no visible binding for global variable 'd'


This is just a note, you can either ignore it or use a dirty trick to
circumvent Luke's checks by
    d <- get("d")
Perhaps it is better to get from the correct environment by specifying it.

Uwe


> Here is the minimal package skeleton:
>
>> d <- data.frame(a=1)
>>
>> f <- function(x)
>> {
>> data("d")
>> x+d$a
>> }
>>
>> package.skeleton(list=c("f","d"), name="mypkg")
>
>
> What would be a sensible way to refer to this data inside the package?
>
> Best regards,
>
> baptiste
>
> _____________________________
>
> Baptiste Auguié
>
> Physics Department
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
>
> Phone: +44 1392 264187
>
> http://newton.ex.ac.uk/research/emag
> http://projects.ex.ac.uk/atto
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

baptiste auguie
Thanks, that works for me!

On 1 Jan 2008, at 15:47, Uwe Ligges wrote:

>
> baptiste Auguié wrote:
>> Dear all,
>> Happy new year!
>> I posted a very similar question a few days ago, but probably too  
>> cluttered. Here is a tidy, minimal version:
>> I want to make a package, with a data.frame d and a function f  
>> given  below. Now, the function f needs to use the data.frame d. I  
>> could  (and that's what I've done temporarily) make a local  
>> duplicate of  this data.frame in the function definition, but it  
>> seems silly.
>> I've tried "attach()", "data()", but both fail when running R CMD  
>> check with the error
>>> * checking R code for possible problems ... NOTE
>>> f: no visible binding for global variable 'd'
>
>
> This is just a note, you can either ignore it or use a dirty trick  
> to circumvent Luke's checks by
>    d <- get("d")
> Perhaps it is better to get from the correct environment by  
> specifying it.
>
> Uwe

I know you're right, but I have no idea which one to pick: the  
environment help page confuses me a lot.

Thanks again,

baptiste

>
>
>> Here is the minimal package skeleton:
>>> d <- data.frame(a=1)
>>>
>>> f <- function(x)
>>> {
>>> data("d")
>>> x+d$a
>>> }
>>>
>>> package.skeleton(list=c("f","d"), name="mypkg")
>> What would be a sensible way to refer to this data inside the  
>> package?
>> Best regards,
>> baptiste
>>

_____________________________

Baptiste Auguié

Physics Department
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
http://projects.ex.ac.uk/atto

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Uwe Ligges


baptiste Auguié wrote:

> Thanks, that works for me!
>
> On 1 Jan 2008, at 15:47, Uwe Ligges wrote:
>>
>> baptiste Auguié wrote:
>>> Dear all,
>>> Happy new year!
>>> I posted a very similar question a few days ago, but probably too  
>>> cluttered. Here is a tidy, minimal version:
>>> I want to make a package, with a data.frame d and a function f given  
>>> below. Now, the function f needs to use the data.frame d. I could  
>>> (and that's what I've done temporarily) make a local duplicate of  
>>> this data.frame in the function definition, but it seems silly.
>>> I've tried "attach()", "data()", but both fail when running R CMD  
>>> check with the error
>>>> * checking R code for possible problems ... NOTE
>>>> f: no visible binding for global variable 'd'
>>
>>
>> This is just a note, you can either ignore it or use a dirty trick to
>> circumvent Luke's checks by
>>    d <- get("d")
>> Perhaps it is better to get from the correct environment by specifying
>> it.
>>
>> Uwe
>
> I know you're right, but I have no idea which one to pick: the
> environment help page confuses me a lot.

d <- get("d", pos=globalenv())

Uwe


> Thanks again,
>
> baptiste
>
>>
>>
>>> Here is the minimal package skeleton:
>>>> d <- data.frame(a=1)
>>>>
>>>> f <- function(x)
>>>> {
>>>>     data("d")
>>>>     x+d$a
>>>> }
>>>>
>>>> package.skeleton(list=c("f","d"), name="mypkg")
>>> What would be a sensible way to refer to this data inside the package?
>>> Best regards,
>>> baptiste
>>>
>
> _____________________________
>
> Baptiste Auguié
>
> Physics Department
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
>
> Phone: +44 1392 264187
>
> http://newton.ex.ac.uk/research/emag
> http://projects.ex.ac.uk/atto
> ______________________________
>
>
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Dan Kelley
The technique
    d <- get("d", pos=globalenv())
doesn't work for me.  It just says that it cannot get "d", even though I have a data/d.rda file.

Do I have to do something special with namespaces, to find it?  

PS. a possibly-related link is as follows.

http://www.nabble.com/how-to-make-read-only-data-frames--tp14756183p14756183.html
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Benilton Carvalho
have you tried
data()
instead?
b

On Jan 20, 2008, at 3:21 PM, Dan Kelley wrote:

>
> The technique
>    d <- get("d", pos=globalenv())
> doesn't work for me.  It just says that it cannot get "d", even  
> though I
> have a data/d.rda file.
>
> Do I have to do something special with namespaces, to find it?
>
> PS. a possibly-related link is as follows.
>
> http://www.nabble.com/how-to-make-read-only-data-frames--tp14756183p14756183.html
> --
> View this message in context: http://www.nabble.com/access-data-inside-package-tp14565386p14986337.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Dan Kelley
Yes, data() works, but then I have this warning from "R CMD check" on my package, so I think I should not be doing it that way.


Benilton Carvalho wrote
have you tried
data()
instead?
b
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Benilton Carvalho
then combine system.file() with load().
b

On Jan 20, 2008, at 3:40 PM, Dan Kelley wrote:

>
> Yes, data() works, but then I have this warning from "R CMD check"  
> on my
> package, so I think I should not be doing it that way.
>
>
>
> Benilton Carvalho wrote:
>>
>> have you tried
>> data()
>> instead?
>> b
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/access-data-inside-package-tp14565386p14986576.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Dan Kelley
My "R CMD check" gives me

  fit.tide: no visible binding for global variable ‘tideconst’

when I do

   load(paste(system.file(package="oce"),"data/tidesetup.rda",sep="/"))
   ... try to use tideconst ...
where tidesetup.rda holds, among other things, a variable named "tideconst".

I guess I can see why -- there is nothing in the file name that tells which variables are contained therein.

I'm sorry to be a bother on this.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Uwe Ligges-3
In reply to this post by Dan Kelley
hits=-2.6 tests=BAYES_00
X-USF-Spam-Flag: NO


First call

   data("d")

then everything is fine already - except that codetools are moaning
around. Those codetools can be calmed down by the line we had already:

   d <- get("d", pos=globalenv())

Uwe Ligges



Dan Kelley wrote:

> Yes, data() works, but then I have this warning from "R CMD check" on my
> package, so I think I should not be doing it that way.
>
>
>
> Benilton Carvalho wrote:
>> have you tried
>> data()
>> instead?
>> b
>>
>>
>>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Duncan Murdoch
In reply to this post by Dan Kelley
On 20/01/2008 3:21 PM, Dan Kelley wrote:

> The technique
>     d <- get("d", pos=globalenv())
> doesn't work for me.  It just says that it cannot get "d", even though I
> have a data/d.rda file.
>
> Do I have to do something special with namespaces, to find it?  
>
> PS. a possibly-related link is as follows.
>
> http://www.nabble.com/how-to-make-read-only-data-frames--tp14756183p14756183.html

If you put it in data/d.rda, then it doesn't get loaded until you
request it via a call to data().  That's why the get() doesn't work.

I think you have two choices:

In some file in your R directory, create the object d.  You might do
this by putting the file into inst/something and loading it from there,
or you might just include R source that creates it.

Alternatively, put it in the special sysdata.rda file in the R
directory.  See Writing R Extensions "Package Subdirectories" for
instructions.

You probably want to specify LazyLoad: yes for your package, so that
objects don't take up memory until actually referenced.

In either of these cases, the object d will be visible to users as soon
as your package is loaded.  If you don't want that, you should use a
namespace for your package.

Duncan Murdoch

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: access data inside package

Dan Kelley
In reply to this post by Uwe Ligges-3
Thanks, Uwe, this works perfectly.


Uwe Ligges-3 wrote
hits=-2.6 tests=BAYES_00
X-USF-Spam-Flag: NO


First call

   data("d")

then everything is fine already - except that codetools are moaning
around. Those codetools can be calmed down by the line we had already:

   d <- get("d", pos=globalenv())

Uwe Ligges



Dan Kelley wrote:
> Yes, data() works, but then I have this warning from "R CMD check" on my
> package, so I think I should not be doing it that way.
>
>
>
> Benilton Carvalho wrote:
>> have you tried
>> data()
>> instead?
>> b
>>
>>
>>
>

______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

R and samr under Linux

markaoki
hi,

This is my first day with R, pls pardon my newbie gaffs.



Im running under Linux, samr V1.25 and R (V2.4.1 and 2.6.1), 32 and 64 bit.



Either way, when I run using samr library I get the error:

"samr is not a valid package - installed < 2.0.0?"



I see in R source code a conditional leading to this message:

pfile <-system.file ("Meta", "package.rds", package=package, libloc =
which.lib.loc);



The samr does not have a "Meta" directory, or underlying package.rds, as the
other

packages have. So, it seems to fail this check.



1. It seems to me that the offered Linux samr package V1.25 is not
compatible with

these versions (2.4 / 2.6) of R. Is this a correct conclusion?



2. R seems to be an interpreted language, and its 'libraries' seem to be
just text files. Thus, it seems I could find a Windows implementation of
samr and copy it to my Linux. Any ideas about this theory?



3. Does R language have a way for me to define which processor in a cluster
I would

like to execute a section of code upon, like in MPI?



Please let me know some of these things, if you can help.

Thanks for helping me,

-m.aoki

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: R and samr under Linux

markaoki
hi,
I have determined some of my own answers, so will share here.

There are binary associations within the R libraries specific to the
environment
that created them, be it Windows or Linux, 32 or 64 bit. I found these
associations in the
Meta directory of the libraries. So, R libraries cannot be shared across
different
platforms as I had hoped as R libraries have a binary component.

As for samr, and some of the other Linux packages available, these packages
must first be
compiled by R, which in so doing produces the 'missing' Meta directory,
among other
critical output.

The procedure I used for Linux was to download a package, for example samr.
I then extracted its contents, which produced a 'samr' directory.

I changed to that directory and, from a command line, issued the following:

#R CMD INSTALL -l samr samr

This compiles the directory (last argument) into the library samr (first
argument),
the best that I can determine anyway.

The result was yet another samr directory containing all of the expected
contents, including the
Meta directory, under this one.

I copied this samr directory to:
/usr/lib64/R/library

...and repeated these steps for the 'impute' library, apparently needed by
samr, and
then tried again to run the developer's software (I didn't write it) and it
worked.

So, Im up and running on 64-bit Linux and R / samr.
Maybe these steps are not the best, but they worked for me.

Hope this helps any other newbies out there : )!

-mark aoki


----- Original Message -----
From: "markaoki" <[hidden email]>
To: <[hidden email]>
Sent: Sunday, January 20, 2008 2:39 PM
Subject: [R] R and samr under Linux


> hi,
>
> This is my first day with R, pls pardon my newbie gaffs.
>
>
>
> Im running under Linux, samr V1.25 and R (V2.4.1 and 2.6.1), 32 and 64
> bit.
>
>
>
> Either way, when I run using samr library I get the error:
>
> "samr is not a valid package - installed < 2.0.0?"
>
>
>
> I see in R source code a conditional leading to this message:
>
> pfile <-system.file ("Meta", "package.rds", package=package, libloc =
> which.lib.loc);
>
>
>
> The samr does not have a "Meta" directory, or underlying package.rds, as
> the
> other
>
> packages have. So, it seems to fail this check.
>
>
>
> 1. It seems to me that the offered Linux samr package V1.25 is not
> compatible with
>
> these versions (2.4 / 2.6) of R. Is this a correct conclusion?
>
>
>
> 2. R seems to be an interpreted language, and its 'libraries' seem to be
> just text files. Thus, it seems I could find a Windows implementation of
> samr and copy it to my Linux. Any ideas about this theory?
>
>
>
> 3. Does R language have a way for me to define which processor in a
> cluster
> I would
>
> like to execute a section of code upon, like in MPI?
>
>
>
> Please let me know some of these things, if you can help.
>
> Thanks for helping me,
>
> -m.aoki
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: R and samr under Linux

James W. MacDonald
Hi Mark,

markaoki wrote:

> hi,
> I have determined some of my own answers, so will share here.
>
> There are binary associations within the R libraries specific to the
> environment
> that created them, be it Windows or Linux, 32 or 64 bit. I found these
> associations in the
> Meta directory of the libraries. So, R libraries cannot be shared across
> different
> platforms as I had hoped as R libraries have a binary component.
>
> As for samr, and some of the other Linux packages available, these packages
> must first be
> compiled by R, which in so doing produces the 'missing' Meta directory,
> among other
> critical output.
>
> The procedure I used for Linux was to download a package, for example samr.
> I then extracted its contents, which produced a 'samr' directory.
>
> I changed to that directory and, from a command line, issued the following:
>
> #R CMD INSTALL -l samr samr
>
> This compiles the directory (last argument) into the library samr (first
> argument),
> the best that I can determine anyway.
>
> The result was yet another samr directory containing all of the expected
> contents, including the
> Meta directory, under this one.
>
> I copied this samr directory to:
> /usr/lib64/R/library
>
> ...and repeated these steps for the 'impute' library, apparently needed by
> samr, and
> then tried again to run the developer's software (I didn't write it) and it
> worked.
>
> So, Im up and running on 64-bit Linux and R / samr.
> Maybe these steps are not the best, but they worked for me.
>
> Hope this helps any other newbies out there : )!

I think your intentions are good, but your advice is actually horrible!

All you needed was (from within R):

install.packages("samr", dependencies=TRUE)

which will install the package correctly, along with any required
dependencies.

Best,

Jim


>
> -mark aoki
>
>
> ----- Original Message -----
> From: "markaoki" <[hidden email]>
> To: <[hidden email]>
> Sent: Sunday, January 20, 2008 2:39 PM
> Subject: [R] R and samr under Linux
>
>
>> hi,
>>
>> This is my first day with R, pls pardon my newbie gaffs.
>>
>>
>>
>> Im running under Linux, samr V1.25 and R (V2.4.1 and 2.6.1), 32 and 64
>> bit.
>>
>>
>>
>> Either way, when I run using samr library I get the error:
>>
>> "samr is not a valid package - installed < 2.0.0?"
>>
>>
>>
>> I see in R source code a conditional leading to this message:
>>
>> pfile <-system.file ("Meta", "package.rds", package=package, libloc =
>> which.lib.loc);
>>
>>
>>
>> The samr does not have a "Meta" directory, or underlying package.rds, as
>> the
>> other
>>
>> packages have. So, it seems to fail this check.
>>
>>
>>
>> 1. It seems to me that the offered Linux samr package V1.25 is not
>> compatible with
>>
>> these versions (2.4 / 2.6) of R. Is this a correct conclusion?
>>
>>
>>
>> 2. R seems to be an interpreted language, and its 'libraries' seem to be
>> just text files. Thus, it seems I could find a Windows implementation of
>> samr and copy it to my Linux. Any ideas about this theory?
>>
>>
>>
>> 3. Does R language have a way for me to define which processor in a
>> cluster
>> I would
>>
>> like to execute a section of code upon, like in MPI?
>>
>>
>>
>> Please let me know some of these things, if you can help.
>>
>> Thanks for helping me,
>>
>> -m.aoki
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.

--
James W. MacDonald, M.S.
Biostatistician
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623

______________________________________________
[hidden email] 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.