From h.wickham at gmail.com  Mon May  4 16:17:35 2015
From: h.wickham at gmail.com (Hadley Wickham)
Date: Mon, 4 May 2015 09:17:35 -0500
Subject: [Rd] Define replacement functions
In-Reply-To: <925F72C7-1611-4AE5-911B-D4DA89D180B9@posteo.ch>
References: <925F72C7-1611-4AE5-911B-D4DA89D180B9@posteo.ch>
Message-ID: <CABdHhvHPs07Khh1PATxg_NgxcB0byox-vm5rxq=s-gr1GxhUnA@mail.gmail.com>

Did you export the S3 methods in the NAMESPACE?

Hadley

On Mon, May 4, 2015 at 7:52 AM,  <soeren.vogel at posteo.ch> wrote:
> Hello
>
> I tried to define replacement functions for the class "mylist". When I test them in an active R session, they work -- however, when I put them into a package, they don't. Why and how to fix?
>
>
> make_my_list <- function( x, y ) {
>         return(structure(list(x, y, class="mylist")))
> }
> mylist <- make_my_list(1:4, letters[3:7])
> mylist
> mylist[['x']] <- 4:6
> mylist
> "[[<-" <- function(x, field, value) {
>         UseMethod('[[<-', x)
> }
> "[[<-.mylist" <- function(x, field, value) {
>         stop( "Do not assign." )
> }
> mylist[['x']] <- 1:10
> mylist
> mylist$y <- LETTERS[1:3]
> mylist
> "$<-" <- function(x, field, value) {
>         UseMethod('$<-', x)
> }
> "$<-.mylist" <- function(x, field, value) {
>         stop( "Do not assign." )
> }
> mylist$y <- LETTERS[10:15]
>
>
> Thanks for help
> S?ren
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
http://had.co.nz/



[Rd] Define replacement functions
Hadley Wickham