similar to: Proper way to document print( ) functions

Displaying 20 results from an estimated 5000 matches similar to: "Proper way to document print( ) functions"

2019 Jul 07
3
Possible bug in `class<-` when a class-specific '[[.' method is defined
Hi all ! I noticed a strange behaviour of the function `class<-` when a class-specific '[[.' method is defined. Here below a reproducible example : #-------------------------------------------------------------------. counttt <- 0 `[[.MYCLASS` = function(x, ...) { counttt <<- counttt + 1 # browser() x = NextMethod() return(x) } df <- as.data.frame(matrix(1:20,
2006 Feb 03
6
Rails from the command line
I have controller that processes data in one table and puts results in another. Now that its'' working, I would like to be able to run it from the command line ( read: windows batch file). How can this be done? It will be installed on a Windows box with InstantRails1.0, (if that matters). I will be doing more processes like this, so this is a good opportunity to get it right. -- Best
2002 Dec 17
3
Changing "..." inside a function: impossible? desirable?
This is was something like a request for your comments, thoughts on the topic... Many of you will know that the "..." (aka \dots) argument is very useful for passing ``further graphical parameters'', but can be a pain when itself is passed to too many plotting functions inside your own function. An artificial example being myplot <- function(x,y, ...) { plot(0:1, 0:1,
2009 Jan 03
1
Equivalent of match for data.frame
Dear R-users, I am translating a S script into R and having some troubles with the match function. This function appears to work with vector and data.frame in S, but not in R, e.g.: a <- rep((1:4), each = 10) b <- rep((1:10), times = 4) mydf <- data.frame(a,b) myarg <- mydf[1,] match(myarg, mydf) # S returns 1 but R returns NA NA I guess one could use match(interaction(myarg),
2019 Jul 15
4
Possible bug in `class<-` when a class-specific '[[.' method is defined
Hello, Clean R 3.6.1 session on Ubuntu 19.04, RStudio 1.1.453. sessionInfo() at the end. I can reproduce this. counttt <- 0 `[[.MYCLASS` = function(x, ...) { counttt <<- counttt + 1 # browser() x = NextMethod() return(x) } df <- as.data.frame(matrix(1:20, nrow=5)) class(df) <- c("MYCLASS","data.frame") counttt #[1] 9 But there's more. I
2010 Jan 15
2
processing all files with certain extension in a directory
Hi all, I'm trying to process all files with a certain extension "*.ext" in a directory like this: > R --slave --args /my/dir < dir_plot.r where I then I want to do something like: myarg <- commandArgs() inputdir <- myarg[length(myarg)] print(inputdir) "for file with extension "*.ext in inputdir" do data = process.data(file) outfile =
2011 May 26
1
Is it possible to define a function's arguments via a wildcard in 'substitute()'?
Dear List, just out of pure curiosity: is it possible to define a function via 'substitute()' such that the function's formal arguments are specified by a "wildcard" that is substituted when the expression is evaluated? Simple example: x.args <- formals("data.frame") x.body <- expression( out <- myArg + 100, return(out) ) expr <-
2006 Nov 24
1
Missing values for S4 slots
Using R 2.4, the following fails: setClass("testc", representation(a="ANY")) makeC <- function(myarg) new("testc", a=myarg) makeC() -> Error in initialize(value, ...) : argument "myarg" is missing, with no default On the other hand, this is OK: f <- function(a) g(b=a) g <- function(b) if(missing(b)) "missing" else "valid
2019 Nov 03
5
Puzzled about a new method for "[".
I recently tried to write a new method for "[", to be applied to data frames, so that the object returned would retain (all) attributes of the columns, including attributes that my code had created. I thrashed around for quite a while, and then got some help from Rui Barradas who showed me how to do it, in the following manner: `[.myclass` <- function(x, i, j, drop = if
2011 Jun 06
1
How can I write methods for 'as()'?
Dear list, I wonder how to write methods for the function 'as' in the sense that I can call 'as(object, Class, strict=TRUE, ext)' and let method dispatch figure out the correct method. AFAIU, there is a difference between, e.g. 'as.data.frame' and the methods of 'as()' as stated above since the former depends on arg 'x' instead of 'object',
2003 Oct 02
1
"[[<-","[[" default?
Hi! I have implemented class specific behaviour of "[[<-.myclass"<-function(). How it is posible to call the "[[.default" on an object of myclass? Eryk Dipl. bio-chem. Eryk Witold Wolski @ MPI-MG Dep. Vertebrate Genomics Ihnestrasse 73 14195 Berlin 'v' tel: 0049-30-84131285 / \ mail: wolski@molgen.mpg.de ---W-W----
2014 Apr 14
1
duplication regression (?)
Below is an example of output that changed as a result of r64970. I did not see any NEWS item suggesting this change is expected. Note that the example is contrived and I don't have a use case for it. I stumbled across it when playing with recent changes in R relating to duplication. Does the example use undefined syntax? ----- fn1 <- function(mylist) { fn1a <- function()
2019 Nov 03
2
Puzzled about a new method for "[".
On 4/11/19 10:31 AM, Duncan Murdoch wrote: > On 03/11/2019 4:11 p.m., Rolf Turner wrote: >> >> I recently tried to write a new method for "[", to be applied to data >> frames, so that the object returned would retain (all) attributes of the >> columns, including attributes that my code had created. >> >> I thrashed around for quite a while, and
2005 Dec 07
1
Dots argument in apply method
Hello everyone, I'm working on a package using S4 classes and methods and I ran into the following "problem" when I tried to create an "apply" method for objects of one of my new classes. I've found a way around the problem but I wonder if I did not paint myself into the corner. I'd like your opinion about that. So I have an object "myObj" of class
2007 Mar 30
2
Replacing slot of S4 class in method of S4 class?
Dear all, Assume that I have an S4 class "MyClass" with a slot "myname", which is initialized to: myname="" in method("initialize"): myclass <- new("MyClass", myname="") Assume that class "MyClass" has a method "mymethod": "mymethod.MyClass" <- function(object, myname=character(0), ...) {
2011 Oct 31
1
Question about copying reference objects using the initialize method
Dears, I have a question about copying reference objects using the initialize method. 1) If the latter has no arguments, there is no problem to copy an object. myClass = setRefClass("myClass", fields = list(value = "numeric") ) myClass$methods(initialize = function(...){ ? value <<- 1 ? callSuper(...) }) newObject = myClass$new() newObject$value = 2 copyObject =
2008 Dec 22
1
How to add a slot to S4 class of an existing package?
Dear all, Since my package is based on S4 classes, I would like to know how to add a slot to an existing S4 class without breaking the code of users of my package. Assume the following S4 class: setClass("MyClass", representation(name = "character", type = "character", data = "data.frame" ), prototype(name =
2011 Sep 22
1
R.oo: do work on data member at construction
Hello, I'd like to 'do work' on data members upon construction (i.e. without implementing it in a get method). Is this the best way to create data member 'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex I'll run into issues. setConstructorS3("MyClass", function(x=NA,y=NA,...) { this <- extend(Object(), "MyClass",
2009 Jan 02
1
"registering" a generic method for a class
Sorry in advance if this is too simple a question, but I'm stuck with some odd behavior and I can't find the text to rid myself of this (admittedly somewhat trivial) problem. Note that I've done generic programming with S3 "objects" in the past, but I've never really dabbled in creating S4 objects until now. So, I've created a new S4 class, call it
2009 Feb 11
1
setClassUnion with numeric; extending class union
Dear list: I am looking for a good way to create an S4 class that would extend numeric, but would allow NULL instead of data as well. As far as I can see there is no way at the moment to do that, but please correct me if I am wrong. The best solution I came up with so far was the following (it also indicates a problem of using setClassUnion with numeric as one of the classes): I define a class