SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: Error with Matrix::rowSums() [ Reply ]
By: Facundo Muñoz on 2015-07-22 10:51
[forum:42392]
Maybe it is a misinterpretation of mine, but I would cite the book "R packages" by Hadley Wickham. In particular the Section about name spaces:
http://r-pkgs.had.co.nz/namespace.html

Some extracts:

- This can be confusing [talking about naming conflicts]. Instead, you can explicitly refer to specific functions: Hmisc::summarize() and plyr::summarize() ... While conflicts aren’t the end of the world because you can always use :: to disambiguate

- In fact, this is what I recommend: list the package in DESCRIPTION so that it’s installed, then always refer to it explicitly with pkg::fun()

- If you are using just a few functions from another package, my recommendation is to note the package name in the Imports: field of the DESCRIPTION file and call the function(s) explicitly using ::, e.g., pkg::fun().

I have certainly not yet understood namespaces... :)
would you point me to some reasons why this is not good practice? (or some documentation on the subject)

Thanks for your time.

RE: Error with Matrix::rowSums() [ Reply ]
By: Martin Maechler on 2015-07-21 15:10
[forum:42382]
Sorry to insist ... but

> It is recommended practice to use :: within a package to avoid naming conflicts, and I have followed this guideline so far.

this is *not* at all true. Whoever recommends this practice has not yet understood name spaces.
To the contrrary: It is *not* good practice... apart from very special and rare situations where it may be necessary
e.g. with expressions and eval()...

Can you please reveal the source of this recommendation, so I can try to get "them" change it?

Best regards,
Martin Maechler (here talking as member of the R Core team)

RE: Error with Matrix::rowSums() [ Reply ]
By: Facundo Muñoz on 2015-07-21 14:07
[forum:42381]
Thanks for the confirmation.

I have my R up to date. But I am using Matrix within a package, and in principle I am reluctant to put more restrictions on versions (either of R or packages) than necessary.

So I am currently using option (1) by importing Matrix (in NAMESPACE), which is not a bad option. However, I am not entirely comfortable with it. It is recommended practice to use :: within a package to avoid naming conflicts, and I have followed this guideline so far.

Thanks in any case.
Facundo.-

RE: Error with Matrix::rowSums() [ Reply ]
By: Martin Maechler on 2015-07-20 07:11
[forum:42378]
You are right: In old version of R, I can reproduce your problem.

But R 3.2.0 has been out for a while, even 3.2.1 and 3.2.2 is going to be released in 3 weeks.

Also: There's really no reason to use Matrix::rowSums() : rowSums() is a generic function and Matrix defines methods for it in a correct way. So, whenever Matrix is loaded and you use rowSums() on Matrix-objects, the correct method is called anyway.

You have two possibilities each of which solves your problem
(and yes, I know that you know this..):

1) use rowSums() instead of Matrix:: rowSums()
2) upgrade your version of R -- which I would strongly recommend anyway.

Best regards,
Martin Maechler

RE: Error with Matrix::rowSums() [ Reply ]
By: Martin Maechler on 2015-07-18 16:27
[forum:42371]
I cannot at all reproduce your problem.

when I execute your code, I get '1' as I should.

You must have mixed up your R environment somehow.

Start 'R --vanilla' and then do the above... and I'm almost sure you wont see the problem...

Error with Matrix::rowSums() [ Reply ]
By: Facundo Muñoz on 2015-07-16 14:37
[forum:42370]
Error reproduced on Linux and Windows systems (both 32 and 64 bit)
Error reproduced in R versions 3.0-2; 3.1-1 and 3.1-3 (but works fine in R 3.2-0 and later)
Error reproduced with package Matrix versions 1.1-4; 1.2-0; 1.2-1 and 1.2-2

MRE:
```
library(Matrix)
testm <- as(as.matrix(TRUE), 'lsCMatrix')
Matrix::rowSums(testm)
```

This gives the following error message:
"Error in callGeneric():
'callGeneric' must be called from a generic function of method"

However,
```
rowSums(testm)
```
works as expected.

Why is it a problem to call rowSums with the package qualification?
I do this within some functions, to avoid using inadvertedly the function from `base`.

Thanks to:
Vienna University of Economics and Business Powered By FusionForge