-4

I would like to modify the "ace" function of the "ape" package according to the author's suggestion. I wrote the modified function to "ace2.r" and want to replace the standard "ace" function from the package by my function (seen here: How to edit and debug R library sources):

insertSource("ace2.r", package= "ape", functions="ace")

but I get

Warning message: In insertSource("ace2.r", package = "ape", functions = "ace"): cannot insert these (not found in source): "ace"

I checked ?insertSource but I don't get what should be given for "functions"

jibbah
  • 29
  • 5
  • Hello Jibbah. Please read [How to Create a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve) and update your question. As currently stated, it's too vague to be effectively answered. – Len Greski Jun 24 '18 at 21:30
  • As background, why do you want to do this? I'm guessing it could harm the reproducibility of your work. If you want to use a custom function, why not just load it with `source("path/to/your/function.R")` at the start of a new script? Possibly related: https://stackoverflow.com/questions/1189759/expert-r-users-whats-in-your-rprofile – Adam Smith Jun 24 '18 at 21:37
  • so I reformulated my question. I followed Adam Smith's and Selcuk Akbas' suggestions and stored the modified function into a new script. However I would still like to know how to implement these changes into the package's function – jibbah Jun 25 '18 at 10:05

1 Answers1

0

Modifying a function is a bit complex and risky, you can create your modified version with a new name. Let's say that function is substr

Write substr in console and press enter, which will return

> substr
function (x, start, stop) 
{
if (!is.character(x)) 
x <- as.character(x)
.Internal(substr(x, as.integer(start), as.integer(stop)))
}
<bytecode: 0x000000000d7d4ec0>
<environment: namespace:base>

then assign your own version with a new name (my_substr)

my_substr <- function (x, start, stop) 
{
if (!is.character(x)) 
x <- as.character(x)
.Internal(substr(x, as.integer(start), as.integer(stop)+1))
}
Selcuk Akbas
  • 711
  • 1
  • 8
  • 20