[Rd] Dependency problem for "hasArg"

2012-07-02 Thread Mauricio Zambrano-Bigiarini

Dear list,

I'm running an R script which first line is:

#!/usr/bin/Rscript

While running that script from the system console (in Red Hat 
Enterprise Linux 6) I got the following error:



Error in plot2(x = sim, y = obs, plot.type = "single", main = 
paste("Daily",  :

  could not find function "hasArg"
Calls: plot_results -> plot_out -> ggof -> plot2


However, if I call EXACTLY the same script from the R console, by using

> source("myRscript.R")

I do not get any error.


As you can see in the error message, the function 'plot_results' calls 
'plot_out' (both in the hydroPSO package). Then 'plot_out' calls the 
function 'ggof', which in turn calls 'plot2' (the latter 2 in the 
hydroGOF package), and 'plot2' has a call to 'hasArg'.



The package 'hydroGOF' exports all its functions by using:

exportPattern("^[^\\.]")

At the other hand, the package 'hydroPSO' does not import any function 
of the 'hydroGOF' package, because the call to 'ggof' only occurs within 
the 'plot_out' function if the hydroGOF package is detected on the user 
machine:


if (!require(hydroGOF)) {
 stop("Invalid argument: You don't have the 'hydroGOF' package !!")
} else {
  library(hydroGOF)
  ggof()
}

Do I have to explicitly import 'ggof' and 'plot2' on the 'hydroPSO' 
package in order to avoid this error or is there any better solution ?


sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.utf8   LC_NUMERIC=C
 [3] LC_TIME=en_GB.utf8LC_COLLATE=en_GB.utf8
 [5] LC_MONETARY=en_GB.utf8LC_MESSAGES=en_GB.utf8
 [7] LC_PAPER=CLC_NAME=C
 [9] LC_ADDRESS=C  LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C

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

other attached packages:
[1] lhs_0.7  hydroPSO_0.1-57  hydroGOF_0.3-3-1 hydroTSM_0.3-4-5
[5] xts_0.8-6Lisflood_0.2-10  zoo_1.7-7

loaded via a namespace (and not attached):
 [1] automap_1.0-12 class_7.3-4cluster_1.14.2 e1071_1.6 
grid_2.15.0   [6] gstat_1.0-12   Hmisc_3.9-3lattice_0.20-6 
proj4_1.0-7rgdal_0.7-12  [11] sp_0.9-99  tools_2.15.0




Any help would be very much appreciated.

Kind regards,

Mauricio Zambrano-Bigiarini

--

Water Resources Unit
Institute for Environment and Sustainability (IES)
Joint Research Centre (JRC), European Commission
webinfo: http://floods.jrc.ec.europa.eu/

DISCLAIMER:\ "The views expressed are purely those of th...{{dropped:11}}

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


Re: [Rd] Dependency problem for "hasArg"

2012-07-02 Thread Charlie Friedemann
The error message you are getting makes it rather clear what the problem is. 
R is unable to find the function 'hasArg'.  As the hasArg function is part
of the package 'methods', a solution would be to put require(methods) at the
beginning of your script.

For whatever reason, loading R via Rscript does not load the base package
"methods" whereas loading the R console does. I'm not entirely sure why this
is the case, and I'm sure someone who knows more about the differences
between the two could chime in here.

--
View this message in context: 
http://r.789695.n4.nabble.com/Dependency-problem-for-hasArg-tp4635147p4635158.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] Dependency problem for "hasArg"

2012-07-02 Thread Dirk Eddelbuettel

On 2 July 2012 at 09:23, Charlie Friedemann wrote:
| The error message you are getting makes it rather clear what the problem is. 
| R is unable to find the function 'hasArg'.  As the hasArg function is part
| of the package 'methods', a solution would be to put require(methods) at the
| beginning of your script.
| 
| For whatever reason, loading R via Rscript does not load the base package
| "methods" whereas loading the R console does. I'm not entirely sure why this
| is the case, and I'm sure someone who knows more about the differences
| between the two could chime in here.

That was a design decision in Rscript as loading 'methods' is slow.  And
FWIW, littler does the same:

  edd@max:~$ r -e'print(search())'
  [1] ".GlobalEnv"   "Autoloads""package:base"
  edd@max:~$ r -lmethods -e'print(search())'
  [1] ".GlobalEnv"  "package:methods" "Autoloads"   "package:base"   
  edd@max:~$ 

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


Re: [Rd] Dependency problem for "hasArg"

2012-07-02 Thread Dirk Eddelbuettel

On 2 July 2012 at 12:00, Dirk Eddelbuettel wrote:
| 
| On 2 July 2012 at 09:23, Charlie Friedemann wrote:
| | The error message you are getting makes it rather clear what the problem 
is. 
| | R is unable to find the function 'hasArg'.  As the hasArg function is part
| | of the package 'methods', a solution would be to put require(methods) at the
| | beginning of your script.
| | 
| | For whatever reason, loading R via Rscript does not load the base package
| | "methods" whereas loading the R console does. I'm not entirely sure why this
| | is the case, and I'm sure someone who knows more about the differences
| | between the two could chime in here.
| 
| That was a design decision in Rscript as loading 'methods' is slow.  And
| FWIW, littler does the same:
| 
|   edd@max:~$ r -e'print(search())'
|   [1] ".GlobalEnv"   "Autoloads""package:base"
|   edd@max:~$ r -lmethods -e'print(search())'
|   [1] ".GlobalEnv"  "package:methods" "Autoloads"   "package:base"   
|   edd@max:~$ 

Maybe I should revisit this, though, as littler beats Rscript even when
loading methods --- and I could then argue that little is less confusing :)

edd@max:~$ time r -e 'q("no")'

real0m0.366s
user0m0.604s
sys 0m0.304s
edd@max:~$ time r -lmethods -e 'q("no")'

real0m0.420s
user0m0.648s
sys 0m0.476s
edd@max:~$ time Rscript -e 'q("no")'

real0m0.485s
user0m0.712s
sys 0m0.544s
edd@max:~$ 

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


Re: [Rd] Dependency problem for "hasArg"

2012-07-02 Thread Martin Morgan

On 07/02/2012 06:23 PM, Charlie Friedemann wrote:

The error message you are getting makes it rather clear what the problem is.
R is unable to find the function 'hasArg'.  As the hasArg function is part
of the package 'methods', a solution would be to put require(methods) at the
beginning of your script.


But I think the idea will be to import(methods) in HydroGOF, since the 
package requires these imports to function properly, and import'ing will 
mean that hasArg does not have to be found on the (user-controlled) 
search path.


Martin



For whatever reason, loading R via Rscript does not load the base package
"methods" whereas loading the R console does. I'm not entirely sure why this
is the case, and I'm sure someone who knows more about the differences
between the two could chime in here.

--
View this message in context: 
http://r.789695.n4.nabble.com/Dependency-problem-for-hasArg-tp4635147p4635158.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



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

Location: Arnold Building M1 B861
Phone: (206) 667-2793

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


[Rd] S4 class for chunked data that inherits from numeric- numeric methods won't work

2012-07-02 Thread Elizabeth Sander
Dear R-devel,

I've created an S4 class called "range.vec", which is meant to hold a
sequence of numbers, like one you would create using seq(). I'm trying to
only store a chunk of the sequence at any given time, to save memory. this
means that my class has slots for start, end, and step, as well as a cached
chunk slot and a slot for where the chunk is indexed within the complete
sequence vector.

I have functional get() and set() methods for chunking, along with '[',
'length', '[[', and 'el', and the class inherits from "numeric". However,
when I try to use a numeric method like 'mean', the function returns NaN
(other numeric methods output different errors).

>From debugging, I've learned that methods like "mean" are successfully
accessing my range.vec methods, but since there is no data stored in .Data,
the functions can't run correctly. I want the numeric methods to use my
chunking functions to access the data, but even after extensive searching
(Green/Blue books, WRE, R internals, and other S4 resources), I haven't
figured out how to use .Data to point to a function, or more generally, how
to get numeric methods to work with my class. Any pointers or suggestions
would be greatly appreciated. Thanks!

Note: I’m running R 2.15.1 on Windows XP from a binary.

Thanks,

Liz Sander
Microstrain
Williston, VT

setClass("range.vec",
representation(start = "numeric",
end = "numeric",
step = "numeric",
chunk = "numeric",
chunkpos = "numeric"),
contains="numeric"  #so that it inherits from ‘vector’ without assuming
logical data
)

setGeneric("set.chunk", function(x,...) standardGeneric("set.chunk"))
setMethod("set.chunk",
signature(x = "range.vec"),
function (x, chunksize=100, chunkpos=1)
{
#This function extracts a chunk of data from the range.vec object.
begin <- x@start + (chunkpos - 1)*x@step
end <- x@start + (chunkpos + chunksize - 2)*x@step
data <- seq(begin, end, x@step) #calculate values in data chunk

#get rid of out-of-bounds values
data[data > x@end] <- NA

x@chunk <- data
x@chunkpos <- chunkpos
return(x)
}
}
)

[[alternative HTML version deleted]]

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


[Rd] Questions about imports to a namespace

2012-07-02 Thread Simon Knapp
Hi,

I am a bit unsure about using imports in packages and have a few
questions. I'm sure the answer to some of these is 'it depends', but
I'm interested in what others think and 'best practices' when this is
the case.



1) If I use an import or importFrom declaration in a NAMESPACE, should
I also qualify the package in calls to the imported function (e.g.
maptools::readShapePoly)?

2) If the 'best practice' is to qualify the calls, when does one stop;
e.g. is it good/bad to say base::sapply?

3) If one is calling a (S3) generic, should one qualify the namespace?
Can this cause problems?

4) Is it better to check for arguments that are missing, or use a
default value of, say, NA; i.e. is missing(arg) preferable to
is.na(arg)?

5) I would like to declare a (S3) generic 'cleanup(x)' but
'cleanup(...)' already exists in R.utils, which my package depends on.
Should I do it?

6) I am used to writing 'requires(package)' for each package I use
within a function. If I have used import or importFrom in my
NAMESPACE, should I still do this?



Looking forward to your advice,
Simon Knapp

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