How to modify and use a function of an R package?

use*_*437 3 r function

My question is regarding How do you adjust/control the scale in a treemap (using the 'portfolio' library) in R?.

I modified seq(-1,0 to seq(0,1 as recommended in one of the answers. I then copied and pasted the entire map.market function into R, but am unable to call the modified version that I just pasted. When I type map.market, the original definition of the function "portfolio" is printed within the R editor window. How can I run the version that I just pasted?

Ric*_*mos 6

如果您只是复制和粘贴,该功能并未真正保存在您的会话中.您需要将其分配给R中的对象.当您键入函数的名称时map.market,您将获得以下代码:

function(...)
{
# all
# the code 
# of the function
}
<bytecode: 0x0000000007dd9aa0>
<environment: namespace:portfolio>
Run Code Online (Sandbox Code Playgroud)

所以,你必须之前所有内容复制<bytecode><environment>线,修改并保存到一个对象

map.market2 = function(...)
{
# all
# the code 
# of the function (with modifications)
}
Run Code Online (Sandbox Code Playgroud)

现在,您可以map.market2根据需要使用新修改的功能.您可以map.market根据需要为其命名,但检查不会破坏其余代码.例如,如果您之前使用过原始函数,因为新修改的函数将优先于原始函数.