如何修改和使用R包的功能? [英] How to modify and use a function of an R package?

查看:70
本文介绍了如何修改和使用R包的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于.

我按照答案之一的建议将 seq(-1,0 修改为 seq(0,1 ),然后复制并粘贴整个 map.market 函数插入R中,但无法调用我刚刚粘贴的修改版本.当我键入 map.market 时,函数"portfolio"的原始定义会打印在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?

推荐答案

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

If you just copy and paste, the function is not really saved in your session. You need to assign it to an object in R. When you type the name of the function map.market, you get the code:

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

因此,您必须复制< bytecode> < environment> 行之前的所有内容,并将其修改并保存到对象

So, you have to copy everything before <bytecode> and <environment> lines, modify and save it to an object

map.market2 = function(...)
{
# all
# the code 
# of the function (with modifications)
}

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

Now, you can use the new modified function map.market2 as desired. You can name it map.market if you want, but check that doesn't break the rest of your code. For example, if you have used the original function before, because the new modified function will have precedence over the original one.

这篇关于如何修改和使用R包的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆