首页 \ 问答 \ 如何将未导出的函数添加到R包(How to add unexported functions to R Package)

如何将未导出的函数添加到R包(How to add unexported functions to R Package)

我正在研究一个R Package其中包含几个我在一个导出函数中使用的函数。

我的问题,可能是一个愚蠢的问题,我应该把所有这些未导出的函数放在哪里? 或者我怎样才能做到这一点?

我不想让用户从R/目录访问此功能。

这是我的虚构函数,它使用未导出的函数add

my_func <- function(x, y){
   result <- exp(add(x, y))
   return(result)
   }

这里是我的虚构函数add我不想导出:

add <- function(x, y) {
 result <- x + y
 return(result)
}

谢谢

编辑

如果我将所有功能放在/R它们将对用户“可见”。 例如, xgboost包中的xgboost是未导出的,但您仍然可以使用xgboost:::generate.cv.folds来访问它,并且我想要这样做。


I am working on a R Package with several functions that I use in one exported function.

My question, probably a silly one, is where am I supposed to put all these unexported functions? Or how can I make this possible?

I don't want to let user access this functions from R/ directory.

Here is my fictitious function that uses the unexported function add:

my_func <- function(x, y){
   result <- exp(add(x, y))
   return(result)
   }

And here is my fictitious function add that I do not want to export:

add <- function(x, y) {
 result <- x + y
 return(result)
}

Thank you

EDIT

If I put all functions in /R they will be "visible" for user. For example, generate.cv.folds from xgboost package is unexported but you still can access it with xgboost:::generate.cv.foldsand I want to do the same.


原文:https://stackoverflow.com/questions/47305211
更新时间:2023-11-16 15:11

最满意答案

您可以在子元素的click事件处理程序中使用事件对象的stopPropagation方法:

$('.io-sidebar-section-advanced-toggle').click(function(e){
    e.stopPropagation();
    $(this).parent().next().children('.io-sidebar-link-advanced').fadeToggle('fast',function(){});
});

从jQuery文档中,这是stopPropagation作用:

防止事件冒泡DOM树,防止任何父处理程序被通知事件。

正如评论中所提到的,如果您愿意,也可以在事件处理程序中使用return false (在这种特殊情况下,据我所知 - 它也会导致preventDefault ,这可能不是您想要发生的事情)。 我个人的偏好是使用stopPropagation但这完全取决于你。


You can use the stopPropagation method of the event object inside the click event handler for the child element:

$('.io-sidebar-section-advanced-toggle').click(function(e){
    e.stopPropagation();
    $(this).parent().next().children('.io-sidebar-link-advanced').fadeToggle('fast',function(){});
});

From the jQuery docs, here's what stopPropagation does:

Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

As mentioned in the comments, if you prefer you can alternatively use return false in the event handler (in this particular case, as far as I can tell anyway - it will also cause preventDefault which may not be what you want to happen). My personal preference is to use stopPropagation but it's completely up to you.

相关问答

更多
  • 每次单击.editPost时,单击处理程序都会#updatePost到#updatePost 。 因此,将以下两个单击事件分开。 $('body').on("click", ".editPost", function(){ ..... }); $('#myModal').on('click', '#updatePost', function(){ ... }); Every time you click on .editPost a click handler is attache to # ...
  • 如果我理解你的问题,你就会问如何为一组元素的click事件触发相同的代码,但是希望将被点击的元素的ID作为参数传递给数据。 如果是这样,这将对具有类className所有元素执行此操作... $('.className').click(function(e) { $.ajax({ type: "POST", url: "page.aspx/function", data: "{'id': '" + this.id + "'}", con ...
  • 如果您使用的是jQuery 1.7或更高版本,请使用on() : $(document).on('click', selector, function(){ //do something }); 这会将点击事件绑定到所选元素,并自动将其添加到新元素中。 off()则相反。 If you are using jQuery 1.7 or above, use on(): $(document).on('click', selector, function(){ //do something }); ...
  • 你可以这样做: $(".class1, .class2").click(function () { $(".classer"+$(this).attr('class').substr(-1)).slideToggle("slow"); }); 只要你点击的元素只有一个类。 这.classer被点击的元素中拉出整数并将其附加到.classer 。 所以点击.class2会触发.class2的切换。 You could do this: $(".class1, .class2").click(functi ...
  • 您可以解除已经附加到该元素的事件,然后附加第二个事件处理程序,因此它将是唯一的一个(请注意解除绑定方法)。 $("#foobar").unbind("click").click(function() { alert("second"); }); You can unbind the events already attached to that element, and then attach the second event handler, so it will be the only one (no ...
  • 您可以在子元素的click事件处理程序中使用事件对象的stopPropagation方法: $('.io-sidebar-section-advanced-toggle').click(function(e){ e.stopPropagation(); $(this).parent().next().children('.io-sidebar-link-advanced').fadeToggle('fast',function(){}); }); 从jQuery文档中,这是stopProp ...
  • 你是什么意思它没有用? 我做了这个小提琴,它起作用: http : //jsfiddle.net/TEyJZ/ (点击时看看图片上面的小图片) 你确定你没有使用错误的选择器吗? (datepicker使它听起来更像是一个datepicker插件) What do you mean it didn' work? I made this fiddle an it works: http://jsfiddle.net/TEyJZ/ (look at the small a above the images whe ...
  • 你可能会大大过度工作。 假设有这样的常规结构:
    你可以立刻得到所有这些...像这样: $('#container img').click(function () { $(this).next('div').show(); }); 为了确定如何在click处理程序 ...
  • 您必须将事件处理程序放在$(document).ready()事件中: $(document).ready(function() { $("#btnSubmit").click(function(){ alert("button"); }); }); You have to put the event handler in the $(document).ready() event: $(document).ready(function() { $("#btnSu ...
  • 您需要像这样cache原始函数引用 var originalOn = jQuery.fn.on; jQuery.fn.on = function() { console.log(arguments[ 0 ] + ' will be bound'); originalOn.apply( this, arguments ); }; 在这里,我们存储对jQuerys原始.on函数的引用。 然后我们覆盖处理程序,但是我们使用Function.prototype.apply使用相同的contex ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)