Re: [Rd] package NAMESPACE question

2014-01-26 Thread Duncan Murdoch

On 14-01-25 6:05 PM, Axel Urbiz wrote:

Thanks again all. Essentially, this is the section of the code that is
causing trouble. This is part of the (exported) function which calls
contr.none (not exported). As mentioned, when I call the exported function
it complains with the error described before.


   oldcontrasts <- unlist(options("contrasts"))
 if (cts)
 options(contrasts = c(unordered = "contr.none", ordered =
"contr.diff"))
 x <- model.matrix(terms(reformulate(var_names)), mf, contrasts)
 options(contrasts = oldcontrasts)


This is hugely incomplete.  Please stop wasting everyone's time, and 
post something reproducible.


Duncan Murdoch

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


[Rd] Trouble installing package in development version of R

2014-01-26 Thread Roberta Jankowski
Dear R-devel,

I'm trying to get practice learning more about the internals of R so am
experimenting with the development version. I successfully cloned the SVN
repo and built and installed R. I am using 2014-01-23 r64861.

However, I cannot seem to install the lattice package. I tried within R
using install.packages and got the error
sh: 1: 1: not found

I then downloaded the tar.gz and tried it as follows:
$ sudo R CMD INSTALL lattice_0.20-24.tar.gz

* installing to library ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1’
* installing *source* package ‘lattice’ ...
** package ‘lattice’ successfully unpacked and MD5 sums checked
** libs
sh: 1: 1: not found
ERROR: compilation failed for package ‘lattice’
* removing ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/lattice’

I then looked at the help for R CMD INSTALL and saw debug flag so I did:
$ sudo R CMD INSTALL -d lattice_0.20-24.tar.gz
processing ‘lattice_0.20-24.tar.gz’
a file
* installing to library ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1’
* build_help_types=
* DBG: 'R CMD INSTALL' now doing do_install()
* created lock directory
‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/00LOCK-lattice’
* installing *source* package ‘lattice’ ...
** package ‘lattice’ successfully unpacked and MD5 sums checked
** libs
about to run R CMD SHLIB -o lattice.so init.c threeDplot.c
sh: 1: 1: not found
ERROR: compilation failed for package ‘lattice’
* removing ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/lattice’


I then did
$ cd lattice/src
$ R CMD SHLIB -d -o lattice.so init.c threeDplot.c
sh: 1: 1: not found

I'm interested in two things.
1 does anyone know what's going on?
2. how could I have figured this out myself? What could I have done
differently for the R CMD SHLIB command to get more output (for example
where this line of code was)?

I have read R installation and administration manual but I did not
understand a lot so I'm probably missing something that is in there but I'm
not sure what.

Thank you for your patience,

Roberta

[[alternative HTML version deleted]]

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


Re: [Rd] Trouble installing package in development version of R

2014-01-26 Thread Duncan Murdoch

On 14-01-26 12:44 AM, Roberta Jankowski wrote:> Dear R-devel,
>
> I'm trying to get practice learning more about the internals of R so am
> experimenting with the development version. I successfully cloned the SVN
> repo and built and installed R. I am using 2014-01-23 r64861.
>
> However, I cannot seem to install the lattice package. I tried within R
> using install.packages and got the error
> sh: 1: 1: not found

That message comes from "sh", the command shell that R is running.

>
> I then downloaded the tar.gz and tried it as follows:
> $ sudo R CMD INSTALL lattice_0.20-24.tar.gz
>
> * installing to library ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1’
> * installing *source* package ‘lattice’ ...
> ** package ‘lattice’ successfully unpacked and MD5 sums checked
> ** libs
> sh: 1: 1: not found

Same here.  However, notice that some install messages printed, so the 
install started, it just failed partway through.


> ERROR: compilation failed for package ‘lattice’
> * removing ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/lattice’
>
> I then looked at the help for R CMD INSTALL and saw debug flag so I did:
> $ sudo R CMD INSTALL -d lattice_0.20-24.tar.gz
> processing ‘lattice_0.20-24.tar.gz’
> a file
> * installing to library ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1’
> * build_help_types=
> * DBG: 'R CMD INSTALL' now doing do_install()
> * created lock directory
> ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/00LOCK-lattice’
> * installing *source* package ‘lattice’ ...
> ** package ‘lattice’ successfully unpacked and MD5 sums checked
> ** libs
> about to run R CMD SHLIB -o lattice.so init.c threeDplot.c
> sh: 1: 1: not found
> ERROR: compilation failed for package ‘lattice’
> * removing ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/lattice’

So it looks as though R CMD SHLIB is the step that failed.  You can look 
it up in Writing R Externals, it is supposed to compile those C files 
into the output lattice.so.  Something is going wrong here.
My guess is that you don't have the compiler installed, or R CMD SHLIB 
is looking in the wrong place, or something like that.

>
>
> I then did
> $ cd lattice/src
> $ R CMD SHLIB -d -o lattice.so init.c threeDplot.c
> sh: 1: 1: not found
>
> I'm interested in two things.
> 1 does anyone know what's going on?
> 2. how could I have figured this out myself? What could I have done
> differently for the R CMD SHLIB command to get more output (for example
> where this line of code was)?

You can look at the online help within R, ?SHLIB, and it will tell you 
that -n will give you some diagnostic information.  You can also try


R CMD SHLIB --help

to see a bit more.

One other thing you can do if you need to ask here again, is to post 
system and version information printed by R by sessionInfo().  And 
please don't post in HTML.


Duncan Murdoch

>
> I have read R installation and administration manual but I did not
> understand a lot so I'm probably missing something that is in there 
but I'm

> not sure what.
>
> Thank you for your patience,
>
> Roberta
>
>[[alternative HTML version deleted]]
>
>
>
> __
> 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] package NAMESPACE question

2014-01-26 Thread Axel Urbiz
Hi Duncan,

My most sincere apologies. It's really not my intention to waste anyones
time. More the opposite...for some reason I thought that the problem had to
do with my call to options() and thought that would be enough. Here's
something reproducible:

I built a foo package based on the code under the "" below. In the
namespace file, I've only exported: trt and cmt (not contr.none and
contr.diff). Notice that cmt calls contr.none and contr.diff by default.

Then in R, I run this code and I get this error message:

library(foo)
set.seed(1)
dd <- data.frame(y = rbinom(100, 1, 0.5), treat = rbinom(100, 1, 0.5), x =
rnorm(100),
 f = gl(4, 250, labels = c("A", "B", "C", "D")))
dd2 <- cmt(y ~ x + f + trt(treat), data =dd)
> Error in get(ctr, mode = "function", envir = parent.frame()) :
   object 'contr.none' of mode 'function' was not found

Thanks,
Axel.



trt <- function(x) x

cmt <- function(formula, data, subset, na.action = na.pass, cts = TRUE)  {

  if (!inherits(formula, "formula"))
stop("Method is only for formula objects.")
  mf <- match.call(expand.dots = FALSE)
  args <- match(c("formula", "data", "subset", "na.action"),
names(mf), 0)
  mf <- mf[c(1, args)]
  mf$drop.unused.levels <- TRUE
  mf[[1]] <- as.name("model.frame")
  special <- "trt"
  mt <- if(missing(data)) terms(formula, special) else terms(formula,
special, data = data)
  mf$formula <- mt
  mf <- eval.parent(mf)
  Terms <- attr(mf, "terms")
  attr(Terms, "intercept") <- 0
  trt.var <- attr(Terms, "specials")$trt
  ct <- mf[, trt.var]
  y <- model.response(mf, "numeric")
  var_names <- attributes(Terms)$term.labels[-(trt.var-1)]
  treat.names <- levels(as.factor(ct))
  oldcontrasts <- unlist(options("contrasts"))
  if (cts)
options(contrasts = c(unordered = "contr.none", ordered = "contr.diff"))
  x <- model.matrix(terms(reformulate(var_names)),
mf, contrasts)
  options(contrasts = oldcontrasts)
  intercept <- which(colnames(x) == "(Intercept)")
  if (length(intercept > 0)) x <- x[, -intercept]
  return(x)
  }

###
# An alternative contrasts function for unordered factors
# Ensures symmetric treatment of all levels of a factor
###
contr.none <- function(n, contrasts) {
  if (length(n) == 1)
contr.treatment(n, contrasts = n<=2)
  else
contr.treatment(n, contrasts = length(unique(n))<=2)
}

###
# An alternative contrasts function for ordered factors
# Ensures use of a difference penalty for such factors
###
contr.diff <- function (n, contrasts = TRUE)
{
  if (is.numeric(n) && length(n) == 1) {
if (n > 1)
  levs <- 1:n
else stop("not enough degrees of freedom to define contrasts")
  }
  else {
levs <- n
n <- length(n)
  }
  contr <- array(0, c(n, n), list(levs, paste(">=", levs, sep="")))
  contr[outer(1:n,1:n, ">=")] <- 1
  if (n < 2)
stop(gettextf("contrasts not defined for %d degrees of freedom",
  n - 1), domain = NA)
  if (contrasts)
contr <- contr[, -1, drop = FALSE]
  contr
}



On Sun, Jan 26, 2014 at 1:21 PM, Duncan Murdoch wrote:

> On 14-01-25 6:05 PM, Axel Urbiz wrote:
>
>> Thanks again all. Essentially, this is the section of the code that is
>> causing trouble. This is part of the (exported) function which calls
>> contr.none (not exported). As mentioned, when I call the exported function
>> it complains with the error described before.
>>
>>
>>oldcontrasts <- unlist(options("contrasts"))
>>  if (cts)
>>  options(contrasts = c(unordered = "contr.none", ordered =
>> "contr.diff"))
>>  x <- model.matrix(terms(reformulate(var_names)), mf, contrasts)
>>  options(contrasts = oldcontrasts)
>>
>
> This is hugely incomplete.  Please stop wasting everyone's time, and post
> something reproducible.
>
> Duncan Murdoch
>
>

[[alternative HTML version deleted]]

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


[Rd] No repository set, so cyclic dependency check skipped

2014-01-26 Thread Paul Gilbert

When checking a package I am getting

* checking package dependencies ... NOTE
  No repository set, so cyclic dependency check skipped

How/where do I set the repository so I don't get this note?

No doubt this is explained in Writing R Extension, but I have not found it.

Paul

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


Re: [Rd] No repository set, so cyclic dependency check skipped

2014-01-26 Thread Uwe Ligges



On 26.01.2014 17:52, Paul Gilbert wrote:

When checking a package I am getting

* checking package dependencies ... NOTE
   No repository set, so cyclic dependency check skipped

How/where do I set the repository so I don't get this note?


Set a repository (e.g,. via optiopns(repos=) in your .Rprofile.

Best,
Uwe Ligges




No doubt this is explained in Writing R Extension, but I have not found it.

Paul

__
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] No repository set, so cyclic dependency check skipped

2014-01-26 Thread Uwe Ligges



On 26.01.2014 18:48, Paul Gilbert wrote:



On 01/26/2014 12:31 PM, Uwe Ligges wrote:



On 26.01.2014 17:52, Paul Gilbert wrote:

When checking a package I am getting

* checking package dependencies ... NOTE
   No repository set, so cyclic dependency check skipped

How/where do I set the repository so I don't get this note?


Set a repository (e.g,. via optiopns(repos=) in your .Rprofile.


I'm getting this note when I check in R-devel on your win-builder site.
Does that mean I need to set .Rprofile or you do?


Agh, I have not set it for the on-demand checks, will do so soon.

Uwe






Best,
Paul



Best,
Uwe Ligges




No doubt this is explained in Writing R Extension, but I have not
found it.

Paul

__
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] No repository set, so cyclic dependency check skipped

2014-01-26 Thread Paul Gilbert



On 01/26/2014 12:31 PM, Uwe Ligges wrote:



On 26.01.2014 17:52, Paul Gilbert wrote:

When checking a package I am getting

* checking package dependencies ... NOTE
   No repository set, so cyclic dependency check skipped

How/where do I set the repository so I don't get this note?


Set a repository (e.g,. via optiopns(repos=) in your .Rprofile.


I'm getting this note when I check in R-devel on your win-builder site. 
Does that mean I need to set .Rprofile or you do?


Best,
Paul



Best,
Uwe Ligges




No doubt this is explained in Writing R Extension, but I have not
found it.

Paul

__
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] package NAMESPACE question

2014-01-26 Thread Duncan Murdoch

On 14-01-26 9:34 AM, Axel Urbiz wrote:> Hi Duncan,
>
> My most sincere apologies. It's really not my intention to waste anyones
> time. More the opposite...for some reason I thought that the problem had
> to do with my call to options() and thought that would be enough. Here's
> something reproducible:
>
> I built a foo package based on the code under the "" below. In the
> namespace file, I've only exported: trt and cmt (not contr.none and
> contr.diff). Notice that cmt calls contr.none and contr.diff by default.
>
> Then in R, I run this code and I get this error message:
>
> library(foo)
> set.seed(1)
> dd <- data.frame(y = rbinom(100, 1, 0.5), treat = rbinom(100, 1, 0.5), x
> = rnorm(100),
>   f = gl(4, 250, labels = c("A", "B", "C", "D")))
> dd2 <- cmt(y ~ x + f + trt(treat), data =dd)
>  > Error in get(ctr, mode = "function", envir = parent.frame()) :
> object 'contr.none' of mode 'function' was not found

In your call to model.matrix in cmt, you pass "contrasts" without 
defining it.  This looks like an error, though it wouldn't cause the 
message you saw, it's likely it would cause some strange problem.


I haven't tried putting your code in a package to see what difference 
that makes.  It's your job to make a reproducible example, not mine.


Duncan Murdoch


>
> Thanks,
> Axel.
>
> 
>
> trt <- function(x) x
>
> cmt <- function(formula, data, subset, na.action = na.pass, cts = 
TRUE)  {

>if (!inherits(formula, "formula"))
>  stop("Method is only for formula objects.")
>mf <- match.call(expand.dots = FALSE)
>args <- match(c("formula", "data", "subset", "na.action"),
>  names(mf), 0)
>mf <- mf[c(1, args)]
>mf$drop.unused.levels <- TRUE
>mf[[1]] <- as.name ("model.frame")
>special <- "trt"
>mt <- if(missing(data)) terms(formula, special) else terms(formula,
> special, data = data)
>mf$formula <- mt
>mf <- eval.parent(mf)
>Terms <- attr(mf, "terms")
>attr(Terms, "intercept") <- 0
>trt.var <- attr(Terms, "specials")$trt
>ct <- mf[, trt.var]
>y <- model.response(mf, "numeric")
>var_names <- attributes(Terms)$term.labels[-(trt.var-1)]
>treat.names <- levels(as.factor(ct))
>oldcontrasts <- unlist(options("contrasts"))
>if (cts)
>  options(contrasts = c(unordered = "contr.none", ordered =
> "contr.diff"))
>x <- model.matrix(terms(reformulate(var_names)),
>  mf, contrasts)
>options(contrasts = oldcontrasts)
>intercept <- which(colnames(x) == "(Intercept)")
>if (length(intercept > 0)) x <- x[, -intercept]
>return(x)
>}
> ###
> # An alternative contrasts function for unordered factors
> # Ensures symmetric treatment of all levels of a factor
> ###
> contr.none <- function(n, contrasts) {
>if (length(n) == 1)
>  contr.treatment(n, contrasts = n<=2)
>else
>  contr.treatment(n, contrasts = length(unique(n))<=2)
> }
>
> ###
> # An alternative contrasts function for ordered factors
> # Ensures use of a difference penalty for such factors
> ###
> contr.diff <- function (n, contrasts = TRUE)
> {
>if (is.numeric(n) && length(n) == 1) {
>  if (n > 1)
>levs <- 1:n
>  else stop("not enough degrees of freedom to define contrasts")
>}
>else {
>  levs <- n
>  n <- length(n)
>}
>contr <- array(0, c(n, n), list(levs, paste(">=", levs, sep="")))
>contr[outer(1:n,1:n, ">=")] <- 1
>if (n < 2)
>  stop(gettextf("contrasts not defined for %d degrees of freedom",
>n - 1), domain = NA)
>if (contrasts)
>  contr <- contr[, -1, drop = FALSE]
>contr
> }
>
>
>
> On Sun, Jan 26, 2014 at 1:21 PM, Duncan Murdoch
> mailto:murdoch.dun...@gmail.com>> wrote:
>
> On 14-01-25 6:05 PM, Axel Urbiz wrote:
>
> Thanks again all. Essentially, this is the section of the code
> that is
> causing trouble. This is part of the (exported) function 
which calls

> contr.none (not exported). As mentioned, when I call the
> exported function
> it complains with the error described before.
>
>
> oldcontrasts <- unlist(options("contrasts"))
>   if (cts)
>   options(contrasts = c(unordered = "contr.none", 
ordered =

> "contr.diff"))
>   x <- model.matrix(terms(__reformulate(var_names)), mf,
> contrasts)
>   options(contrasts = oldcontrasts)
>
>
> This is hugely incomplete.  Please stop wasting everyone's time, and
> post something reproducible.
>
> Duncan Murdoch
>
>

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


Re: [Rd] Trouble installing package in development version of R

2014-01-26 Thread Roberta Jankowski
On Sun, Jan 26, 2014 at 8:54 AM, Duncan Murdoch
 wrote:
> On 14-01-26 12:44 AM, Roberta Jankowski wrote:> Dear R-devel,
>
>>
>> I'm trying to get practice learning more about the internals of R so am
>> experimenting with the development version. I successfully cloned the SVN
>> repo and built and installed R. I am using 2014-01-23 r64861.
>>
>> However, I cannot seem to install the lattice package. I tried within R
>> using install.packages and got the error
>> sh: 1: 1: not found
>
> That message comes from "sh", the command shell that R is running.
>
>
>>
>> I then downloaded the tar.gz and tried it as follows:
>> $ sudo R CMD INSTALL lattice_0.20-24.tar.gz
>>
>> * installing to library ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1’
>> * installing *source* package ‘lattice’ ...
>> ** package ‘lattice’ successfully unpacked and MD5 sums checked
>> ** libs
>> sh: 1: 1: not found
>
> Same here.  However, notice that some install messages printed, so the
> install started, it just failed partway through.
>
>
>> ERROR: compilation failed for package ‘lattice’
>> * removing ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/lattice’
>>
>> I then looked at the help for R CMD INSTALL and saw debug flag so I did:
>> $ sudo R CMD INSTALL -d lattice_0.20-24.tar.gz
>> processing ‘lattice_0.20-24.tar.gz’
>> a file
>> * installing to library ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1’
>> * build_help_types=
>> * DBG: 'R CMD INSTALL' now doing do_install()
>> * created lock directory
>> ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/00LOCK-lattice’
>> * installing *source* package ‘lattice’ ...
>> ** package ‘lattice’ successfully unpacked and MD5 sums checked
>> ** libs
>> about to run R CMD SHLIB -o lattice.so init.c threeDplot.c
>> sh: 1: 1: not found
>> ERROR: compilation failed for package ‘lattice’
>> * removing ‘/home/rjan/R/i686-pc-linux-gnu-library/3.1/lattice’
>
> So it looks as though R CMD SHLIB is the step that failed.  You can look it
> up in Writing R Externals, it is supposed to compile those C files into the
> output lattice.so.  Something is going wrong here.
> My guess is that you don't have the compiler installed, or R CMD SHLIB is
> looking in the wrong place, or something like that.
>
>>
>>
>> I then did
>> $ cd lattice/src
>> $ R CMD SHLIB -d -o lattice.so init.c threeDplot.c
>> sh: 1: 1: not found
>>
>> I'm interested in two things.
>> 1 does anyone know what's going on?
>> 2. how could I have figured this out myself? What could I have done
>> differently for the R CMD SHLIB command to get more output (for example
>> where this line of code was)?
>
> You can look at the online help within R, ?SHLIB, and it will tell you that
> -n will give you some diagnostic information.

Yes this is useful. I thought that -d would provide more useful info
than -n but both are helpful.

> You can also try
>
> R CMD SHLIB --help
>
> to see a bit more.
>
> One other thing you can do if you need to ask here again, is to post system
> and version information printed by R by sessionInfo().  And please don't
> post in HTML.

Done. (I've now checked "plain text" in GMail which I think should to
the trick).

I will do more reading and experimenting. I think for now I should
just learn R better before experimenting further with devel version. I
already learned a lot even though I did not succeed in package
installation so it was a good lesson.

Thank you for your useful replies and for your work on R. I follow
this list now and am learning a lot from your email responses.

Thanks for your patience,

Berta

>
> Duncan Murdoch
>
>
>>
>> I have read R installation and administration manual but I did not
>> understand a lot so I'm probably missing something that is in there but
>> I'm
>> not sure what.
>>
>> Thank you for your patience,
>>
>> Roberta
>>
>>   [[alternative HTML version deleted]]
>>
>>
>>
>> __
>> 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] package NAMESPACE question

2014-01-26 Thread Henrik Bengtsson
On Sun, Jan 26, 2014 at 6:34 AM, Axel Urbiz  wrote:
> Hi Duncan,
>
> My most sincere apologies. It's really not my intention to waste anyones
> time. More the opposite...for some reason I thought that the problem had to
> do with my call to options() and thought that would be enough. Here's
> something reproducible:
>
> I built a foo package based on the code under the "" below. In the
> namespace file, I've only exported: trt and cmt (not contr.none and
> contr.diff). Notice that cmt calls contr.none and contr.diff by default.

As a start, try to export everything, particularly 'contr.none' and
'contr.diff' and see if that works.  Just a guess, but worth trying
out.

My $.02

/Henrik

>
> Then in R, I run this code and I get this error message:
>
> library(foo)
> set.seed(1)
> dd <- data.frame(y = rbinom(100, 1, 0.5), treat = rbinom(100, 1, 0.5), x =
> rnorm(100),
>  f = gl(4, 250, labels = c("A", "B", "C", "D")))
> dd2 <- cmt(y ~ x + f + trt(treat), data =dd)
>> Error in get(ctr, mode = "function", envir = parent.frame()) :
>object 'contr.none' of mode 'function' was not found
>
> Thanks,
> Axel.
>
> 
>
> trt <- function(x) x
>
> cmt <- function(formula, data, subset, na.action = na.pass, cts = TRUE)  {
>
>   if (!inherits(formula, "formula"))
> stop("Method is only for formula objects.")
>   mf <- match.call(expand.dots = FALSE)
>   args <- match(c("formula", "data", "subset", "na.action"),
> names(mf), 0)
>   mf <- mf[c(1, args)]
>   mf$drop.unused.levels <- TRUE
>   mf[[1]] <- as.name("model.frame")
>   special <- "trt"
>   mt <- if(missing(data)) terms(formula, special) else terms(formula,
> special, data = data)
>   mf$formula <- mt
>   mf <- eval.parent(mf)
>   Terms <- attr(mf, "terms")
>   attr(Terms, "intercept") <- 0
>   trt.var <- attr(Terms, "specials")$trt
>   ct <- mf[, trt.var]
>   y <- model.response(mf, "numeric")
>   var_names <- attributes(Terms)$term.labels[-(trt.var-1)]
>   treat.names <- levels(as.factor(ct))
>   oldcontrasts <- unlist(options("contrasts"))
>   if (cts)
> options(contrasts = c(unordered = "contr.none", ordered = "contr.diff"))
>   x <- model.matrix(terms(reformulate(var_names)),
> mf, contrasts)
>   options(contrasts = oldcontrasts)
>   intercept <- which(colnames(x) == "(Intercept)")
>   if (length(intercept > 0)) x <- x[, -intercept]
>   return(x)
>   }
>
> ###
> # An alternative contrasts function for unordered factors
> # Ensures symmetric treatment of all levels of a factor
> ###
> contr.none <- function(n, contrasts) {
>   if (length(n) == 1)
> contr.treatment(n, contrasts = n<=2)
>   else
> contr.treatment(n, contrasts = length(unique(n))<=2)
> }
>
> ###
> # An alternative contrasts function for ordered factors
> # Ensures use of a difference penalty for such factors
> ###
> contr.diff <- function (n, contrasts = TRUE)
> {
>   if (is.numeric(n) && length(n) == 1) {
> if (n > 1)
>   levs <- 1:n
> else stop("not enough degrees of freedom to define contrasts")
>   }
>   else {
> levs <- n
> n <- length(n)
>   }
>   contr <- array(0, c(n, n), list(levs, paste(">=", levs, sep="")))
>   contr[outer(1:n,1:n, ">=")] <- 1
>   if (n < 2)
> stop(gettextf("contrasts not defined for %d degrees of freedom",
>   n - 1), domain = NA)
>   if (contrasts)
> contr <- contr[, -1, drop = FALSE]
>   contr
> }
>
>
>
> On Sun, Jan 26, 2014 at 1:21 PM, Duncan Murdoch 
> wrote:
>
>> On 14-01-25 6:05 PM, Axel Urbiz wrote:
>>
>>> Thanks again all. Essentially, this is the section of the code that is
>>> causing trouble. This is part of the (exported) function which calls
>>> contr.none (not exported). As mentioned, when I call the exported function
>>> it complains with the error described before.
>>>
>>>
>>>oldcontrasts <- unlist(options("contrasts"))
>>>  if (cts)
>>>  options(contrasts = c(unordered = "contr.none", ordered =
>>> "contr.diff"))
>>>  x <- model.matrix(terms(reformulate(var_names)), mf, contrasts)
>>>  options(contrasts = oldcontrasts)
>>>
>>
>> This is hugely incomplete.  Please stop wasting everyone's time, and post
>> something reproducible.
>>
>> Duncan Murdoch
>>
>>
>
> [[alternative HTML version deleted]]
>
> __
> 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