Re: [Rd] combining large list of data.frames

2012-04-24 Thread Cole Beck
Thanks Patrick, this is a nice solution.  Regarding a patch I'm inclined 
to believe you're correct, though it is certainly something to consider.


Cheers,
Cole

On 04/20/2012 07:55 PM, Patrick Aboyoun wrote:

Cole,
Bioconductor's high throughput sequencing infrastructure package IRanges
contains code that may be useful for speeding up base::rbind.data.frame.
I've extracted the salient bits from that rbind method, but left the
corner case handling code out. IRanges's rbind method took the approach
of treating a data set as a list of equal length columns, and so it
contains a number of lapplys and vector concatenation calls. Given that
base::rbind.data.frame sits at the core of many operations, I'm not sure
if patches would be accepted for it, but I could take a crack at it.

biocRBind <- function(..., deparse.level=1)
{
## Simplified version of IRanges's rbind method for DataFrame
## Removed all data checks, ignored row names
args <- list(...)
df <- args[[1L]]
cn <- colnames(df)
cl <- unlist(lapply(as.list(df, use.names = FALSE), class))
factors <- unlist(lapply(as.list(df, use.names = FALSE), is.factor))
cols <- lapply(seq_len(length(df)), function(i) {
cols <- lapply(args, `[[`, cn[i])
if (factors[i]) { # combine factor levels, coerce to character
levs <- unique(unlist(lapply(cols, levels), use.names=FALSE))
cols <- lapply(cols, as.character)
}
combined <- do.call(c, unname(cols))
if (factors[i])
combined <- factor(combined, levs)
as(combined, cl[i])
})
names(cols) <- colnames(df)
do.call(data.frame, cols)
}

# create list of data.frames
set.seed(123)
dat <- vector("list", 2)
for(i in seq_along(dat)) {
size <- sample(1:30, 1)
dat[[i]] <- data.frame(id=rep(i, size), value=rnorm(size),
letter=sample(LETTERS, size, replace=TRUE), ind=sample(c(TRUE,FALSE),
size, replace=TRUE))
}

# sample runs
 > system.time(do.call(biocRBind, dat))
user system elapsed
2.120 0.000 2.125
 > system.time(do.call(biocRBind, dat))
user system elapsed
2.092 0.000 2.091
 > system.time(do.call(biocRBind, dat))
user system elapsed
2.080 0.000 2.077
 > sessionInfo()
R Under development (unstable) (2012-04-19 r59111)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] tools_2.16.0


Cheers,
Patrick


On 4/19/2012 3:34 PM, Cole Beck wrote:

It's normal for me to create a list of data.frames and then use
do.call('rbind', list(...)) to create a single data.frame. However,
I've noticed as the size of the list grows large, it is perhaps better
to do this in chunks. As an example here's a list of 20,000 similar
data.frames.

# create list of data.frames
dat <- vector("list", 2)
for(i in seq_along(dat)) {
size <- sample(1:30, 1)
dat[[i]] <- data.frame(id=rep(i, size), value=rnorm(size),
letter=sample(LETTERS, size, replace=TRUE), ind=sample(c(TRUE,FALSE),
size, replace=TRUE))
}
# combine into one data.frame, normal usage
# system.time(do.call('rbind', dat)) # takes 2-3 minutes
combine <- function(x, steps=NA, verbose=FALSE) {
nr <- length(x)
if(is.na(steps)) steps <- nr
while(nr %% steps != 0) steps <- steps+1
if(verbose) cat(sprintf("step size: %s\r\n", steps))
dl <- vector("list", steps)
for(i in seq(steps)) {
ix <- seq(from=(i-1)*nr/steps+1, length.out=nr/steps)
dl[[i]] <- do.call("rbind", x[ix])
}
do.call("rbind", dl)
}
# combine into one data.frame
system.time(combine(dat, 100)) # takes 5-10 seconds

I'm very surprised by this result. Does this improvement seem
reasonable? I would think "do.call" could utilize something similar by
default when the length of "args" is too high. Is using "do.call" not
recommended in this scenario?

Regards,
Cole Beck

__
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] url, readLines, source behind a proxy

2012-04-24 Thread Renaud Gaujoux


On 23/04/2012 17:39, Prof Brian Ripley wrote:

On 18/04/2012 16:04, Joshua Ulrich wrote:

Hi Renaud,

On Wed, Apr 18, 2012 at 12:22 AM, Renaud Gaujoux
  wrote:

Hi Henrik,





Could anybody behind a proxy check if the issue can be reproduced?
My proxy is in fact provided by cntml, which acts as a local proxy that
takes care of tricky authentication protocols with the actual 
university
proxy, not natively supported by my system (Ubuntu). Anybody in this 
case?



I can replicate this on a WinXP system, where I normally have to use
the --internet2 flag to get internet access through a proxy.

?download.file has a section on "Setting Proxies", which describes how
to use environment variables to set proxy information.  Setting
http_proxy='http://my.proxy.com/' was enough for me to get R CMD
check to run successfully with the --as-cran flag.


I guess that the simplest way on Windows is to ensure that --internet2 
is set.  In R-patched there is a new environment variable 
R_WIN_INTERNET2 which lets you do that (set it in ~/.R/check.Renviron).


[Setting proxies is so 20th century -- even moderately competent 
sysadmins worked out how to use transparent caching proxies ca 1995. 
Which is why the R developers give it a low priority.]
I completely understand the low priority -- fast-illimited-internet 
based --  point of view. I wish I could live without such a fussy proxy, 
but I have not much choice.

I like to understand why things work and do not work though.
Is there any special feature my proxy should have to allow 
readLines/source to correctly read remote data? What makes its access 
different from wget?


Thank you for your insights on this.







Thanks.
Renaud



Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

R/Finance 2012: Applied Finance with R
www.RinFinance.com



On Tue, 17 Apr 2012, Henrik Bengtsson wrote:


On Tue, Apr 17, 2012 at 1:01 AM, Renaud Gaujoux
  wrote:

Hi,

when I run R CMD check with flag --as-cran, the process hangs at 
stage:


* checking CRAN incoming feasibility ...


Doesn't it time-out eventually?  I'm not behind a proxy but when I've
been running 'R CMD check' whenon very poor 3G connection, it had
eventually timed out.

/Henrik



I am pretty sure it is a proxy issue.
I looked at the check code in the tools package and it seems that 
the issue

is in the local function `.repository_db()` (defined in
`tools:::.check_package_CRAN_incoming()`), which eventually calls 
`url()`
with argument open="rb", that hangs probably because it does not 
use the

proxy settings.
I had a similar issue with `source()`, which apparently uses internal
network functions (not as download.file), but is supposed to work 
behind a

proxy (correct?).
Does anybody else have this problem?

I was wondering if there is a way around, as I would like to be 
able to use

--as-cran for my checks.
Thank you.

Renaud

--
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa

__
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


__
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


[Rd] nobs.glm

2012-04-24 Thread Wincent
Hi all,

The nobs method  of (MASS:::polr class) takes into account of weight,
but nobs method of glm does not. I wonder what is the rationale of
such design behind nobs.glm. Thanks in advance. Best Regards.

> library(MASS)
> house.plr <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
> house.logit <- glm(I(Sat=='High') ~ Infl + Type + Cont, binomial,weights = 
> Freq, data = housing)
> nobs(house.plr)
[1] 1681
> nobs(house.logit)
[1] 72


-- 
Wincent Ronggui HUANG
Sociology Department of Fudan University
PhD of City University of Hong Kong
http://homepage.fudan.edu.cn/rghuang/cv/

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


Re: [Rd] nobs.glm

2012-04-24 Thread Prof Brian Ripley

On 24/04/2012 14:36, Wincent wrote:

Hi all,

The nobs method  of (MASS:::polr class) takes into account of weight,
but nobs method of glm does not. I wonder what is the rationale of
such design behind nobs.glm. Thanks in advance. Best Regards.


library(MASS)
house.plr<- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
house.logit<- glm(I(Sat=='High') ~ Infl + Type + Cont, binomial,weights = Freq, 
data = housing)
nobs(house.plr)

[1] 1681

nobs(house.logit)

[1] 72



Well, the interpretation of 'weights' for a GLM depends on the family. 
They may be equivalent to duplicated observations for a binomial GLM, 
but they are not for a Gaussian one.  The nobs method for class "glm" 
(there is no visible nobs.glm) follows the "lm" method.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[Rd] Specifying a function as not being and S3 Class function

2012-04-24 Thread Matt Pocernich

I am compiling a library with legacy code which has functions named with 
periods in the names - but are not S3 class functions.For example for 
example,  summary.agriculture is not an extension of the summary function for 
and 'agriculture. class object - it is just poorly named.  

Is it possible to  keep from triggering the following warning when I check the 
package? 

* checking S3 generic/method consistency ... WARNING

summary:
  function(object, ...)
summary.agriculture:
  function(x, analyte.names, results.col, analyte.col, by, det.col,
   iQuantiles, iDetStats, iSW, iUCL, iLand, conf.level, iUTL,
   tol.level, utl.conf.level, iND, sig.figs)

I know that the best answer would be to rename with a better naming convention, 
but that would cause issues with legacy applications.

Thanks,

Matt

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


[Rd] Where to store and how to load support data ?

2012-04-24 Thread Charles Plessy
Dear R developers,

I am writing a R module, which contains a function that needs support data (a
table with two columns).

I wonder how to make sure the data is available to the function, without making
the function reload the data each time it is executed.  Is it what the lazy
mechanism takes care of ?  Or should I use something like .onLoad ?

Also I am wondering about where the data should be located.  Is ./data 
appropriate ?

Perhaps somebody can suggest the name of a package that I can study to find the
answer myself ?

Have a nice day,

-- 
Charles Plessy
Tsurumi, Kanagawa, Japan

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


Re: [Rd] url, readLines, source behind a proxy

2012-04-24 Thread Henrik Bengtsson
Looking at the source code (src/library/tools/R/check.R and
src/library/tools/R/QC.R), I found that...

WORKAROUND:
You can trick 'R CMD check' to quickly skip the
"check_package_CRAN_incoming" test by providing it with invalid URLs
to repositories by setting system environment
'_R_CHECK_XREFS_REPOSITORIES_' to a non-empty URL. For example:

% export _R_CHECK_XREFS_REPOSITORIES_="invalidURL"
% R CMD check --as-cran ...

gives:

* checking CRAN incoming feasibility ...NB: need Internet access to
use CRAN incoming checks
 OK

/Henrik

On Tue, Apr 24, 2012 at 5:46 AM, Renaud Gaujoux
 wrote:
>
> On 23/04/2012 17:39, Prof Brian Ripley wrote:
>>
>> On 18/04/2012 16:04, Joshua Ulrich wrote:
>>>
>>> Hi Renaud,
>>>
>>> On Wed, Apr 18, 2012 at 12:22 AM, Renaud Gaujoux
>>>   wrote:

 Hi Henrik,

>>> 


 Could anybody behind a proxy check if the issue can be reproduced?
 My proxy is in fact provided by cntml, which acts as a local proxy that
 takes care of tricky authentication protocols with the actual university
 proxy, not natively supported by my system (Ubuntu). Anybody in this
 case?

>>> I can replicate this on a WinXP system, where I normally have to use
>>> the --internet2 flag to get internet access through a proxy.
>>>
>>> ?download.file has a section on "Setting Proxies", which describes how
>>> to use environment variables to set proxy information.  Setting
>>> http_proxy='http://my.proxy.com/' was enough for me to get R CMD
>>> check to run successfully with the --as-cran flag.
>>
>>
>> I guess that the simplest way on Windows is to ensure that --internet2 is
>> set.  In R-patched there is a new environment variable R_WIN_INTERNET2 which
>> lets you do that (set it in ~/.R/check.Renviron).
>>
>> [Setting proxies is so 20th century -- even moderately competent sysadmins
>> worked out how to use transparent caching proxies ca 1995. Which is why the
>> R developers give it a low priority.]
>
> I completely understand the low priority -- fast-illimited-internet based --
>  point of view. I wish I could live without such a fussy proxy, but I have
> not much choice.
> I like to understand why things work and do not work though.
> Is there any special feature my proxy should have to allow readLines/source
> to correctly read remote data? What makes its access different from wget?
>
> Thank you for your insights on this.
>
>
>>
>>
>>>
 Thanks.
 Renaud

>>>
>>> Best,
>>> --
>>> Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
>>>
>>> R/Finance 2012: Applied Finance with R
>>> www.RinFinance.com
>>>
>>>
 On Tue, 17 Apr 2012, Henrik Bengtsson wrote:

> On Tue, Apr 17, 2012 at 1:01 AM, Renaud Gaujoux
>   wrote:
>>
>> Hi,
>>
>> when I run R CMD check with flag --as-cran, the process hangs at
>> stage:
>>
>> * checking CRAN incoming feasibility ...
>
>
> Doesn't it time-out eventually?  I'm not behind a proxy but when I've
> been running 'R CMD check' whenon very poor 3G connection, it had
> eventually timed out.
>
> /Henrik
>
>>
>> I am pretty sure it is a proxy issue.
>> I looked at the check code in the tools package and it seems that the
>> issue
>> is in the local function `.repository_db()` (defined in
>> `tools:::.check_package_CRAN_incoming()`), which eventually calls
>> `url()`
>> with argument open="rb", that hangs probably because it does not use
>> the
>> proxy settings.
>> I had a similar issue with `source()`, which apparently uses internal
>> network functions (not as download.file), but is supposed to work
>> behind a
>> proxy (correct?).
>> Does anybody else have this problem?
>>
>> I was wondering if there is a way around, as I would like to be able
>> to use
>> --as-cran for my checks.
>> Thank you.
>>
>> Renaud
>>
>> --
>> Renaud Gaujoux
>> Computational Biology - University of Cape Town
>> South Africa
>>
>> __
>> 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
>>>
>>>
>>> __
>>> 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

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


[Rd] Using other peoples packages from within C-based R-extension

2012-04-24 Thread oliver
Hello,

what if I want to write a package mixed R/C-extension
and want to use code that is provided by other peoples packages?

How for example can I use one of the provided wavelet packages
from within my C-based R-extension?

Somehow I would need to load the other packages and have access to the
functions they provide.
I mean I don't want to use the other packages via R-level, but directly
on the C-layer. Something like shared libs (dlopen and such stuff)
but via R-API.

Is there a general aproach to this, and how to do it?


Ciao,
   Oliver

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


Re: [Rd] Using other peoples packages from within C-based R-extension

2012-04-24 Thread Duncan Murdoch

On 24/04/2012 12:31 PM, oliver wrote:

Hello,

what if I want to write a package mixed R/C-extension
and want to use code that is provided by other peoples packages?

How for example can I use one of the provided wavelet packages
from within my C-based R-extension?

Somehow I would need to load the other packages and have access to the
functions they provide.
I mean I don't want to use the other packages via R-level, but directly
on the C-layer. Something like shared libs (dlopen and such stuff)
but via R-API.

Is there a general aproach to this, and how to do it?


See "Registering native routines" in the Writing R Extensions manual.

Duncan Murdoch

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


[Rd] Creating model frame from R formula inside compiled code

2012-04-24 Thread Alireza Mahani
I am developing a custom regression package, which accepts a formula object
as way of setting up the model matrix and response variable from a data
frame. For large data sets, I expect that going through R memory might be
too slow, so I'm thinking about reading the data directly into C (e.g. from
a database) and then parsing the formula inside of C (by calling an R
function such as model.frame()). Is this possible? An alternative solution
is to read the large data set into R in chunks, create the model matrix for
each chunk and save the matrix chunk to disk, and then load and piece
together these chunks inside of C. But my solution seems sub-optimal to me.
Any suggestions? Thank you!


--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-model-frame-from-R-formula-inside-compiled-code-tp4584124p4584124.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


Re: [Rd] Specifying a function as not being and S3 Class function

2012-04-24 Thread S Ellison
> Is it possible to  keep from triggering the following warning 
> when I check the package? 
>
> summary:
>   function(object, ...)
> summary.agriculture:
>   function(x, analyte.names, results.col, analyte.col, by, det.col,
> [clip]

Part of the solution is to add ... to the legacy function; that is required by 
the generic and is missing in your own function. Adding ... will not break 
existing code.

The name of the initial argument will still cause problems. But I've kludged 
round a similar issue (an intentional difference in required parameters, in my 
case) by replacing something like

obj.summary(x, y, z, ...) 

with something like
obj.summary(object, y, z, x=object, ...)

This preserves legacy argument order, is consistent with summary(object, ...) 
and retains the named argument x to avoid code changes. 

But it is clearly a kludge. It also runs the risk of accidental overwriting of 
x if someone specifies too many unnamed parameters. That should not happen in 
working legacy code, of course, as that would have broken if you included a 
surplus parameter in a function call with no ... . If it _is_ a problem you 
could try obj.summary(object, y, z, ..., x=object), which would avoid the 
accidental assignment by requiring exact match naming, but I cannot recall 
offhand if that construct would be considered consistent with the generic using 
the current CMD check. 

Steve Ellison

> -Original Message-
> From: r-devel-boun...@r-project.org 
> [mailto:r-devel-boun...@r-project.org] On Behalf Of Matt Pocernich
> Sent: 24 April 2012 16:34
> To: r-devel@r-project.org
> Subject: [Rd] Specifying a function as not being and S3 Class function
> 
> 
> I am compiling a library with legacy code which has functions 
> named with periods in the names - but are not S3 class 
> functions.For example for example,  summary.agriculture 
> is not an extension of the summary function for and 
> 'agriculture. class object - it is just poorly named.  
> 
> Is it possible to  keep from triggering the following warning 
> when I check the package? 
> 
> * checking S3 generic/method consistency ... WARNING
> 
> summary:
>   function(object, ...)
> summary.agriculture:
>   function(x, analyte.names, results.col, analyte.col, by, det.col,
>iQuantiles, iDetStats, iSW, iUCL, iLand, conf.level, iUTL,
>tol.level, utl.conf.level, iND, sig.figs)
> 
> I know that the best answer would be to rename with a better 
> naming convention, but that would cause issues with legacy 
> applications.
> 
> Thanks,
> 
> Matt
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> ***
This email and any attachments are confidential. Any use...{{dropped:8}}

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


Re: [Rd] Using other peoples packages from within C-based R-extension

2012-04-24 Thread Dirk Eddelbuettel

On 24 April 2012 at 12:39, Duncan Murdoch wrote:
| On 24/04/2012 12:31 PM, oliver wrote:
| > Hello,
| >
| > what if I want to write a package mixed R/C-extension
| > and want to use code that is provided by other peoples packages?
| >
| > How for example can I use one of the provided wavelet packages
| > from within my C-based R-extension?
| >
| > Somehow I would need to load the other packages and have access to the
| > functions they provide.
| > I mean I don't want to use the other packages via R-level, but directly
| > on the C-layer. Something like shared libs (dlopen and such stuff)
| > but via R-API.
| >
| > Is there a general aproach to this, and how to do it?
| 
| See "Registering native routines" in the Writing R Extensions manual.

And there are over 120 packages providing access:

   CITAN Cubist GOSim KernSmooth MASS MSBVAR Matrix NetComp PMA PopGenome
   QuACN RCurl RODBC RTextTools Rcpp Rigroup Rlabkey Rmosek Rmpfr Rook Rserve
   Runuran SASxport SMCP SoDA TraMineR XML actuar adaptivetau akima aster
   aster2 bcv bda blme boolfun bstats canvas caret catnet cgh chron class
   climdex.pcic clpAPI clue cluster copula cplexAPI cplm datamap devEMF
   edesign expm fastICA fastcluster ff flsa foreign fracdiff fuzzyRankTests
   gb glpkAPI gmp gputools grpreg gsmoothr heavy hypred ifs ifultools int64
   interactivity kza lattice lfe lme4 locfit lpSolveAPI markdown mgcv minqa
   mugnet ncvreg nlme nnet pedigreemm phangorn phmm potts ppstat qtbase
   qtpaint quadprog rPorta randtoolbox rcdd rdyncall rgeos rggobi rmongodb
   rngWELL robustbase rpart rphast rrp rtfbs sde sensitivityPStrat sp spatial
   spdep spsurvey spt tree tripack uncompress vines xlsReadWrite xts yaml zoo

Matrix and lme4 is the prototypical example by R Core, MASS also provides
something.  I'd probably start with zoo and xts ...

Dirk

PS Rcpp et al don't do it as you can't register C++ routines IIRC.

-- 
R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com

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


[Rd] Write unix format files on windows and vice versa

2012-04-24 Thread Andrew Redd
I go back and forth between windows and linux, and find myself running
into problem with line endings.  Is there a way to control the line
ending conversion when writing files, such as write and cat?  More
explicitly I want to be able to write files with LF line endings
rather than CRLF line ending on windows; and CRLF line endings instead
of LF on linux, and I want to be able to control when the conversion
is made and/or choose the line endings that I want.

As far as I can tell the conversion is not optional and buried deep in
compiled code. Is there a possible work around?

Thanks,
Andrew

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


Re: [Rd] Using other peoples packages from within C-based R-extension

2012-04-24 Thread oliver
Hello, 

OK, thanks for the information...


On Tue, Apr 24, 2012 at 12:02:33PM -0500, Dirk Eddelbuettel wrote:
> 
> On 24 April 2012 at 12:39, Duncan Murdoch wrote:
> | On 24/04/2012 12:31 PM, oliver wrote:
> | > Hello,
> | >
> | > what if I want to write a package mixed R/C-extension
> | > and want to use code that is provided by other peoples packages?
> | >
> | > How for example can I use one of the provided wavelet packages
> | > from within my C-based R-extension?
> | >
> | > Somehow I would need to load the other packages and have access to the
> | > functions they provide.
> | > I mean I don't want to use the other packages via R-level, but directly
> | > on the C-layer. Something like shared libs (dlopen and such stuff)
> | > but via R-API.
> | >
> | > Is there a general aproach to this, and how to do it?
> | 
> | See "Registering native routines" in the Writing R Extensions manual.
> 
> And there are over 120 packages providing access:
> 
>CITAN Cubist GOSim KernSmooth MASS MSBVAR Matrix NetComp PMA PopGenome
>QuACN RCurl RODBC RTextTools Rcpp Rigroup Rlabkey Rmosek Rmpfr Rook Rserve
>Runuran SASxport SMCP SoDA TraMineR XML actuar adaptivetau akima aster
>aster2 bcv bda blme boolfun bstats canvas caret catnet cgh chron class
>climdex.pcic clpAPI clue cluster copula cplexAPI cplm datamap devEMF
>edesign expm fastICA fastcluster ff flsa foreign fracdiff fuzzyRankTests
>gb glpkAPI gmp gputools grpreg gsmoothr heavy hypred ifs ifultools int64
>interactivity kza lattice lfe lme4 locfit lpSolveAPI markdown mgcv minqa
>mugnet ncvreg nlme nnet pedigreemm phangorn phmm potts ppstat qtbase
>qtpaint quadprog rPorta randtoolbox rcdd rdyncall rgeos rggobi rmongodb
>rngWELL robustbase rpart rphast rrp rtfbs sde sensitivityPStrat sp spatial
>spdep spsurvey spt tree tripack uncompress vines xlsReadWrite xts yaml zoo
[...]

But no wavelets stuff... (?)
(It was more than an example, I'm look for wavelet decompositioning.)


> 
> Matrix and lme4 is the prototypical example by R Core, MASS also provides
> something.  I'd probably start with zoo and xts ...
[...]

You mean with "start with" that I could look how to allow exporting
for my own package?

At the moment I'm rather looking for how to import symbols and access 
fnuctionality
of othera people's packages ...


Ciao,
   Oliver

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


Re: [Rd] Write unix format files on windows and vice versa

2012-04-24 Thread Duncan Murdoch

On 24/04/2012 1:23 PM, Andrew Redd wrote:

I go back and forth between windows and linux, and find myself running
into problem with line endings.  Is there a way to control the line
ending conversion when writing files, such as write and cat?  More
explicitly I want to be able to write files with LF line endings
rather than CRLF line ending on windows; and CRLF line endings instead
of LF on linux, and I want to be able to control when the conversion
is made and/or choose the line endings that I want.

As far as I can tell the conversion is not optional and buried deep in
compiled code. Is there a possible work around?


On Windows you will write CRLF if the file was opened as a text file, 
and LF only if it was opened as a binary file.  For example:


writeLines(letters, "crlf.txt")
con <- file("lf.txt", open="wb")
writeLines(letters, con)
close(con)

On Unix you can write CRLF by specifying that as the sep arg.  So the 
following will work on both systems:


con <- file("crlf.txt", open="wb")
writeLines(letters, con, sep="\r\n")
close(con)

(and the explicit connection isn't really necessary on Unix, but it is 
on Windows).


If you're not using the writeLines() function, it's probably a bit 
harder to set CRLF as a default on Unix than it is to set LF as a 
default on Windows.


Duncan Murdoch

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


Re: [Rd] Write unix format files on windows and vice versa

2012-04-24 Thread Ted Harding
On 24-Apr-2012 17:23:00 Andrew Redd wrote:
> I go back and forth between windows and linux, and find myself
> running into problem with line endings. Is there a way to
> control the line ending conversion when writing files, such as
> write and cat? More explicitly I want to be able to write files
> with LF line endings rather than CRLF line ending on windows;
> and CRLF line endings instead of LF on linux, and I want to be
> able to control when the conversion is made and/or choose the
> line endings that I want.
> 
> As far as I can tell the conversion is not optional and buried
> deep in compiled code. Is there a possible work around?
> 
> Thanks,
> Andrew

Rather than write the Linux version out in Windows (or the other
way round in Linux), you might find it more useful to use an
external conversion utility.

One such is unix2dos/dos2unix (the same program in either case,
whose function depends on what name you call it by). This used
to be standard on older Linux systems, but may need to be explicitly
installed on your system. It seems there may also be a version for
Windows -- see:

  http://download.cnet.com/Unix2DOS/3000-2381_4-10488164.html


Then, when you create a file in Windows, you could transfer it to
Linux and covert it to "Unix"; and also keep it as it is for use
on Windows. Conversely, when you create a file in Linux, you
coled convert it to "Windows" and transfer it to Windows; and
also keep it as it is for use on Linux.

It is also possible to do the CRLF-->LF or LF-->CRLF using 'sed'
in Linux.

For some further detail see

   http://en.wikipedia.org/wiki/Unix2dos

Hoping this helps,
Ted.

-
E-Mail: (Ted Harding) 
Date: 24-Apr-2012  Time: 18:56:21
This message was sent by XFMail

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


Re: [Rd] Using other peoples packages from within C-based R-extension

2012-04-24 Thread Jeffrey Ryan
This link may be of help as well...

https://stat.ethz.ch/pipermail/r-devel/2008-November/051262.html


HTH
Jeff

On 4/24/12 12:35 PM, "oliver"  wrote:

>Hello, 
>
>OK, thanks for the information...
>
>
>On Tue, Apr 24, 2012 at 12:02:33PM -0500, Dirk Eddelbuettel wrote:
>> 
>> On 24 April 2012 at 12:39, Duncan Murdoch wrote:
>> | On 24/04/2012 12:31 PM, oliver wrote:
>> | > Hello,
>> | >
>> | > what if I want to write a package mixed R/C-extension
>> | > and want to use code that is provided by other peoples packages?
>> | >
>> | > How for example can I use one of the provided wavelet packages
>> | > from within my C-based R-extension?
>> | >
>> | > Somehow I would need to load the other packages and have access to
>>the
>> | > functions they provide.
>> | > I mean I don't want to use the other packages via R-level, but
>>directly
>> | > on the C-layer. Something like shared libs (dlopen and such stuff)
>> | > but via R-API.
>> | >
>> | > Is there a general aproach to this, and how to do it?
>> | 
>> | See "Registering native routines" in the Writing R Extensions manual.
>> 
>> And there are over 120 packages providing access:
>> 
>>CITAN Cubist GOSim KernSmooth MASS MSBVAR Matrix NetComp PMA
>>PopGenome
>>QuACN RCurl RODBC RTextTools Rcpp Rigroup Rlabkey Rmosek Rmpfr Rook
>>Rserve
>>Runuran SASxport SMCP SoDA TraMineR XML actuar adaptivetau akima
>>aster
>>aster2 bcv bda blme boolfun bstats canvas caret catnet cgh chron
>>class
>>climdex.pcic clpAPI clue cluster copula cplexAPI cplm datamap devEMF
>>edesign expm fastICA fastcluster ff flsa foreign fracdiff
>>fuzzyRankTests
>>gb glpkAPI gmp gputools grpreg gsmoothr heavy hypred ifs ifultools
>>int64
>>interactivity kza lattice lfe lme4 locfit lpSolveAPI markdown mgcv
>>minqa
>>mugnet ncvreg nlme nnet pedigreemm phangorn phmm potts ppstat qtbase
>>qtpaint quadprog rPorta randtoolbox rcdd rdyncall rgeos rggobi
>>rmongodb
>>rngWELL robustbase rpart rphast rrp rtfbs sde sensitivityPStrat sp
>>spatial
>>spdep spsurvey spt tree tripack uncompress vines xlsReadWrite xts
>>yaml zoo
>[...]
>
>But no wavelets stuff... (?)
>(It was more than an example, I'm look for wavelet decompositioning.)
>
>
>> 
>> Matrix and lme4 is the prototypical example by R Core, MASS also
>>provides
>> something.  I'd probably start with zoo and xts ...
>[...]
>
>You mean with "start with" that I could look how to allow exporting
>for my own package?
>
>At the moment I'm rather looking for how to import symbols and access
>fnuctionality
>of othera people's packages ...
>
>
>Ciao,
>   Oliver
>
>__
>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