[Rd] C-Side: Applying a function (given as param) to data (given as param)

2011-06-03 Thread oliver
Hello,

I'm implementing a package (C-extension),
where one function gets data and a function
that needs to be applied to the data.

I want to apply the function to (parts of)
the data on the C-side.

1) how do I apply a function (given via SEXP) to data
2) how do I select parts of the data (also provided via SEXP)?

Comment on 2: I want to implement a moving/rolling/running
apply on the data, so I want to select a data window.
How can this be done, and how can it be done efficiently?

For example on page 101 of "Writing R extensions" there was a trick
on how to use REAL on the result, before using it in a loop.
Can this be used for efficiency reasons in general?


 Ciao,
Oliver


P.S.: What do these macros (like REAL()) do? Do they convert data
  or rather cast datatypes?

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem to execute a function loading by my package that I created

2011-06-03 Thread Po
I still look for my problem.
I think that maybe my Makefile is not good.

In my folder src of my package, I put an existing program. In this program,
I had already a makefile.
So I kept this makefile and I changed.

I saw that it's better to have a file Makevars to compile. But I don't know
what is a file Makevars and I don't know how I can gather the files Makefile
and Makevars together.

Thank you in advance,

Pauline

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-to-execute-a-function-loading-by-my-package-that-I-created-tp3568081p3570314.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Bug or feature: using "ANY" as a generic field class (was: '[R] Is there a (virtual) class that all R objects inherit from?)

2011-06-03 Thread Janko Thyson
Dear list,

I was wondering if you could help me out in clarifying something:
Is it possible to use class "ANY" in slots/fields of formal classes if you
   a) do not want to restrict valid classes of that field and
   b) if you are making explicit use of class inheritance?

It seems to work in simple scenarios but produces errors when class 
inheritance comes into play. So I was wondering if that's a feature or a 
bug.

If using "ANY" is not the right way, I'd appreciate a pointer to how you 
can to this.

See previous post with an example below.

Regards,
Janko

On 06/03/2011 01:53 AM, Janko Thyson wrote:
> On 31.05.2011 18:17, Martin Morgan wrote:
>> On 05/30/2011 07:02 AM, Janko Thyson wrote:
>>> Dear list,
>>>
>>> I would like to set one specific Reference Class field to be of an
>>> arbitrary class. Is there a class that all R objects inherit from? I
>>> thought that "ANY" was something like this, but obviously that's not
>>> true:
>>>
>>> > inherits(1:3, "ANY")
>>> [1] FALSE
>>
>> I can't speak to the implementation, but ANY functions as a base class
>> in terms of slot / field assignment and inheritance, e.g.,
>>
>> setClass("A", representation(x="ANY"))
>> new("A", x=1:3)
>>
>> Martin
>
> Hi Martin,
>
> sorry for the late response. The way you do it works. Yet, when you
> declare dependencies more explicitly (contains=XY), then R complains. Is
> this a feature or a bug (with respect to the "less explicit" way working
> just fine)? See the example below:
>
> # S4
> setClass("A", representation(x="ANY"))
> new("A", x=1:3)
>
> setClass("A", representation(x="ANY"))
> setClass("B", contains="A", representation(x="character"))
> new("B", x=1:3)
>
> # Reference Classes
> setRefClass(
> Class="A",
> fields=list(
> .PRIMARYDATA="ANY"
> ),
> contains=c("VIRTUAL")
> )
> B <- setRefClass(
> Class="B",
> fields=list(
> .PRIMARYDATA="character"
> ),
> contains=c("A")
> )

Bug, I'd say. Martin

>
> Regards,
> Janko
>>>
>>> Regards,
>>> Janko
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> r-h...@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.
>>
>>


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem to execute a function loading by my package that I created

2011-06-03 Thread Simon Urbanek
Pauline,

since you mentioned Rcpp, you're on the wrong list. I have put some comments 
below but they assume you're using regular R packaging and not Rcpp.

On Jun 3, 2011, at 4:41 AM, Po wrote:

> I still look for my problem.
> I think that maybe my Makefile is not good.
> 
> In my folder src of my package, I put an existing program. In this program,
> I had already a makefile.
> So I kept this makefile and I changed.
> 

Thats generally not a safe idea, because R has its own ways of compiling and 
linking so you would have to replicate that. If what you have is a stand-alone 
library, you can put it in a separate directory in your package and have it 
build itself so src will consist of the interface between R and you library 
only.

If what you have is essentially the package code in C++ then you don't need a 
Makefile at all - R will simply compile all sources you put in src and create a 
shared object for the package from it. You don't need to do anything, just 
remove your Makefile.


> I saw that it's better to have a file Makevars to compile. But I don't know 
> what is a file Makevars and I don't know how I can gather the files Makefile 
> and Makevars together.
> 

Makevars is simply a makefile without compilation and linking rules as those 
are provided by R automatically. See recent posts about it on this list.

Cheers,
Simon


> Thank you in advance,
> 
> Pauline
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Problem-to-execute-a-function-loading-by-my-package-that-I-created-tp3568081p3570314.html
> Sent from the R devel mailing list archive at Nabble.com.
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem to execute a function loading by my package that I created

2011-06-03 Thread Po
Thank you for your help Simon. I resolved my issue.
As you told me, I put my C++ program in a separate directory of my package.  I 
create a library with my C++ program. On my package, there are only functions 
called by R and that uses my program.

From: Simon Urbanek [via R] 
[mailto:ml-node+3570897-797271001-242...@n4.nabble.com]
Sent: 03 June 2011 15:04
To: Pauline Ferrouillat
Subject: Re: Problem to execute a function loading by my package that I created

Pauline,

since you mentioned Rcpp, you're on the wrong list. I have put some comments 
below but they assume you're using regular R packaging and not Rcpp.

On Jun 3, 2011, at 4:41 AM, Po wrote:

> I still look for my problem.
> I think that maybe my Makefile is not good.
>
> In my folder src of my package, I put an existing program. In this program,
> I had already a makefile.
> So I kept this makefile and I changed.
>

Thats generally not a safe idea, because R has its own ways of compiling and 
linking so you would have to replicate that. If what you have is a stand-alone 
library, you can put it in a separate directory in your package and have it 
build itself so src will consist of the interface between R and you library 
only.

If what you have is essentially the package code in C++ then you don't need a 
Makefile at all - R will simply compile all sources you put in src and create a 
shared object for the package from it. You don't need to do anything, just 
remove your Makefile.


> I saw that it's better to have a file Makevars to compile. But I don't know 
> what is a file Makevars and I don't know how I can gather the files Makefile 
> and Makevars together.
>

Makevars is simply a makefile without compilation and linking rules as those 
are provided by R automatically. See recent posts about it on this list.

Cheers,
Simon

> Thank you in advance,
>
> Pauline
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Problem-to-execute-a-function-loading-by-my-package-that-I-created-tp3568081p3570314.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> __
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

__
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Makevars-and-Makefile-tp3568081p3570897.html
To unsubscribe from Makevars and Makefile, click 
here.

This email is from The James Hutton Institute (JHI), however the views
expressed by the sender are not necessarily the views of JHI and its
subsidiaries. This email and any attachments are confidential and are intended
solely for the use of the recipient(s) to whom they are addressed.  If you
are not the intended recipient, you should not read, copy, disclose or rely on
any information contained in this email, and we would ask you to contact the
sender immediately and delete the email from your system.  Although JHI has
taken reasonable precautions to ensure no viruses are present in this email,
neither the Institute nor the sender accepts any responsibility for any
viruses, and it is your responsibility to scan the email and any attachments.

The James Hutton Institute is a Scottish charitable company limited by
guarantee.
Registered in Edinburgh No. SC374831
Registered Office: The James Hutton Institute, Invergowrie Dundee DD2 5DA.
Charity No. SC041796

--
View this message in context: 
http://r.789695.n4.nabble.com/Makevars-and-Makefile-tp3568081p3571267.html
Sent from the R devel mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] C-Side: Applying a function (given as param) to data (given as param)

2011-06-03 Thread Douglas Bates
On Fri, Jun 3, 2011 at 5:17 AM, oliver  wrote:
> Hello,
>
> I'm implementing a package (C-extension),
> where one function gets data and a function
> that needs to be applied to the data.
>
> I want to apply the function to (parts of)
> the data on the C-side.
>
> 1) how do I apply a function (given via SEXP) to data
> 2) how do I select parts of the data (also provided via SEXP)?

Not to be facetious but you begin by reading the "Writing R Extensions" manual.

An alternative is to read the vignette Rcpp-Introduction available as
http://dirk.eddelbuettel.com/code/rcpp/Rcpp-introduction.pdf and soon
to be in The R Journal.  They show an explicit example of apply in
compiled code (C++ using the Rcpp structures, in their case).

> Comment on 2: I want to implement a moving/rolling/running
> apply on the data, so I want to select a data window.
> How can this be done, and how can it be done efficiently?
>
> For example on page 101 of "Writing R extensions" there was a trick
> on how to use REAL on the result, before using it in a loop.
> Can this be used for efficiency reasons in general?
>
>
>  Ciao,
>    Oliver
>
>
> P.S.: What do these macros (like REAL()) do? Do they convert data
>      or rather cast datatypes?
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Bug or feature: using "ANY" as a generic field class (was: '[R] Is there a (virtual) class that all R objects inherit from?)

2011-06-03 Thread John Chambers
Well, your mail is unclear as to what you expected, but there is one bug 
shown by your example.


The behavior of S4 classes is sensible, at least as far as the example 
shows:



> setClass("A", representation(x="ANY"))
[1] "A"
> setClass("B", contains="A", representation(x="character"))
[1] "B"
> new("B", x=1:3)
Error in validObject(.Object) :
  invalid class "B" object: invalid object for slot "x" in class "B": 
got class "integer", should be or extend class "character"


You couldn't expect the new() call to work, as the error message clearly 
explains.  A legitimate call does work:


> new("B", x = "abc")
An object of class "B"
Slot "x":
[1] "abc"

The reference classes should work the same way, but don't, as your 
example shows.


A <- setRefClass(
+ Class="A",
+ fields=list(
+ .PRIMARYDATA="ANY"
+ ),
+ contains=c("VIRTUAL")
+ )
> B <- setRefClass(
+ Class="B",
+ fields=list(
+ .PRIMARYDATA="character"
+ ),
+ contains=c("A")
+ )
Error in `insertFields<-`(`*tmp*`, value = "character") :
  The overriding class("character") of field ".PRIMARYDATA" is not a 
subclass of the existing field definition ("ANY")


We'll fix that.  And, yes, "ANY" is intended as a universal superclass, 
but is usually not mentioned explicitly.



On 6/3/11 6:53 AM, Janko Thyson wrote:

Dear list,

I was wondering if you could help me out in clarifying something:
Is it possible to use class "ANY" in slots/fields of formal classes if you
a) do not want to restrict valid classes of that field and
b) if you are making explicit use of class inheritance?

It seems to work in simple scenarios but produces errors when class
inheritance comes into play. So I was wondering if that's a feature or a
bug.

If using "ANY" is not the right way, I'd appreciate a pointer to how you
can to this.

See previous post with an example below.

Regards,
Janko

On 06/03/2011 01:53 AM, Janko Thyson wrote:

On 31.05.2011 18:17, Martin Morgan wrote:

On 05/30/2011 07:02 AM, Janko Thyson wrote:

Dear list,

I would like to set one specific Reference Class field to be of an
arbitrary class. Is there a class that all R objects inherit from? I
thought that "ANY" was something like this, but obviously that's not
true:


inherits(1:3, "ANY")

[1] FALSE


I can't speak to the implementation, but ANY functions as a base class
in terms of slot / field assignment and inheritance, e.g.,

setClass("A", representation(x="ANY"))
new("A", x=1:3)

Martin


Hi Martin,

sorry for the late response. The way you do it works. Yet, when you
declare dependencies more explicitly (contains=XY), then R complains. Is
this a feature or a bug (with respect to the "less explicit" way working
just fine)? See the example below:

# S4
setClass("A", representation(x="ANY"))
new("A", x=1:3)

setClass("A", representation(x="ANY"))
setClass("B", contains="A", representation(x="character"))
new("B", x=1:3)

# Reference Classes
setRefClass(
Class="A",
fields=list(
.PRIMARYDATA="ANY"
),
contains=c("VIRTUAL")
)
B<- setRefClass(
Class="B",
fields=list(
.PRIMARYDATA="character"
),
contains=c("A")
)


Bug, I'd say. Martin



Regards,
Janko


Regards,
Janko

[[alternative HTML version deleted]]

__
r-h...@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-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel