[inlinedocs] Error in 'modify.Rd.file' on '[.' S3 methods

Julien Moeys julien.moeys at slu.se
Fri Nov 30 17:56:08 CET 2012


Thanks Toby

I think I found a solution. The fix was finally easier than what I initially thought.

The part of modify.Rd.file() (in package.skeleton.dx.R) that needs to be changed is:
--- --- ---
  if ( is.null(d$.s3method) ) {
	  # PhG: in case we have fun<-(x, ..., value), we must rewrite it
	  # as fun(x, ...) <- value
	  if (grepl("<-$", N)) {
		  utxt <- sub("<-[(](.+), ([^,)]+)[)]",
				  "(\\1) <- \\2", utxt)
	  }
	  # PhG: this is for special functions %...% which should write x %...% y
	  if (grepl("^%.*%$", N)) {
		  utxt <- sub("(%.*%)[(]([^,]+), ([^)]+)[)]",
				  "\\2 \\1 \\3", utxt) 
	  }
  }
--- --- ---

I have changed it to:

--- --- ---
  if ( is.null(d$.s3method) ) {
	  # PhG: in case we have fun<-(x, ..., value), we must rewrite it
	  # as fun(x, ...) <- value
	  if (grepl("<-$", N)) {
		  utxt <- sub("<-[(](.+), ([^,)]+)[)]",
				  "(\\1) <- \\2", utxt)
	  }
	  # PhG: this is for special functions %...% which should write x %...% y
	  if (grepl("^%.*%$", N)) {
		  utxt <- sub("(%.*%)[(]([^,]+), ([^)]+)[)]",
				  "\\2 \\1 \\3", utxt) 
	  }
  }else{ # JM 
         # JM: in case we have [<-fun( x, ..., value ), we must rewrite it 
         # as x[ ... ] <- value 
      if (grepl("\\[<-\\.", N) | grepl("\\[\\.", N) ) {
		  utxt <- sub( pattern = N, 
            replacement = paste0( "`", N, "`" ), 
            x = utxt, fixed = TRUE ) 
	  }         
  }     
--- --- ---

Which is wrapping the function's name between "`" quotes. And that seems to fix the problem. At least I modified the code and re-compiled the package (--no-examples), and it worked.

I am not sure if that is the right things to do, and I am not sure if that may break's other's code (or not). If I compile the package *with* examples, the compilation fails, but it seems the error does not occur in modify.Rd.file(). I don't know if this is intended or not.

Well, good luck with your PhD and your postdoc Toby. inlinedocs is a great productivity tool!

Cheers

Julien

-----Original Message-----
From: Toby Dylan Hocking [mailto:Toby.Hocking at inria.fr] 
Sent: den 30 november 2012 11:27
To: Julien Moeys
Cc: inlinedocs-support at lists.r-forge.r-project.org
Subject: Re: [inlinedocs] Error in 'modify.Rd.file' on '[.' S3 methods

Thanks for the info Julien. Indeed there is some complexity in the current implementation of modify.Rd.file, and we should simplify it so that bug fixes such as the one you point out are easier to do. I am just finishing my PHD and going on vacation for the month of December, then starting a post-doc in January where I may have some time to look into the issue. However, if you find a solution, please check in the code!


More information about the Inlinedocs-support mailing list