Friday, 15 April 2011

r - edit a function that's in a packages namespace -



r - edit a function that's in a packages namespace -

this first time trying this, apologies if terminology wrong. there's bundle (snapcgh on bioconductor) im using. phone call 1 function, plotsegmentedgenome, in turn calls genomeplot. both functions within snapcgh namespace:

> environment(plotsegmentedgenome) <environment: namespace:snapcgh> > environment(genomeplot) <environment: namespace:snapcgh>

i want edit genomeplot. first effort consisted of running

> genomeplot

so code , create new function that. 2 minor things i'd change. labels x-axis in mb whereas id bp (so multiplying labels no values plotted 1000000). secondly, labels x-axis additionally chromosome in jarring red. id remove label totally. saved effort genomeplot.r , sourced it.

if run plotsegmentedgenome nil changes. presume it's still using hte genomeplot function within namespace. if create own re-create of plotsegmentedgenome in global env, error "error: object 'chrominfo.mb' not found". 1 of arguments plotsegmentedgenome suppose created in env.

i hope makes sense , there's solution isnt embarrisingly easy :)

ps: read this, http://www.r-bloggers.com/environments-in-r/, interesting not quite detailed plenty allow me figure out how prepare this. if write

snapcgh$genomeplot <- customgenomeplot or snapcgh:::genomeplot <- customgenomeplot

update: based on redirect/intercept function calls within bundle function

i tried

library(proto) plotsegmentedgenome <- with(proto(environment( plotsegmentedgenome), plotsegmentedgenome = snapcgh:: plotsegmentedgenome, genomeplot = genomeplot), my_genomeplot)

but still received error

error in plotsegmentedgenome(seginfo.hom.rundnacopy, array = array, chrom.to.plot = 19, : object 'chrominfo.mb' not found >

it calling version of function @ to the lowest degree though, prints message("its alive!") stuck in my_genomeplot

do want edit function permanently? or temporarily?

if want permanent alter should source version of package, modify source code, install bundle changed source. consider contributing changes author/maintainer.

if want temporary alter seek command:

trace(genomeplot, edit=true)

this open editor (you can specify editor if don't want utilize default) source code , allow edit it. when save , exit editor save edited version in place of original taking care of environments/namespaces/etc.

this alter lastly current r session or until phone call untrace function.

r

No comments:

Post a Comment