不完善但有用的功能怎么办? [英] What to do with imperfect-but-useful functions?

查看:99
本文介绍了不完善但有用的功能怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同样可以给这个问题加上标题,对CRAN来说足够好吗?"

I could equally have titled this question, "Is it good enough for CRAN?"

我有一些针对特定任务而建立的功能集合.其中一些是便捷功能:

I have a collection of functions that I've built up for specific tasks. Some of these are convenience functions:

# Returns odds/evens from a vector
odds=function(vec) {
    stopifnot(class(vec)=="integer")
    ret = vec[fpart(vec/2)!=0]
    ret
}
evens=function(vec) {
    stopifnot(class(vec)=="integer")
    ret = vec[fpart(vec/2)==0]
    ret
}

有些是次要的补充,已证明对回答常见的SO问题很有用:

Some are minor additions that have proven useful in answering common SO question:

# Shift a vector over by n spots
# wrap adds the entry at the beginning to the end
# pad does nothing unless wrap is false, in which case it specifies whether to pad with NAs
shift <- function(vec,n=1,wrap=TRUE,pad=FALSE) {
    if(length(vec)<abs(n)) { 
        #stop("Length of vector must be greater than the magnitude of n \n") 
    }
    if(n==0) { 
        return(vec) 
    } else if(length(vec)==n) { 
        # return empty
        length(vec) <- 0
        return(vec)
    } else if(n>0) {
        returnvec <- vec[seq(n+1,length(vec) )]
        if(wrap) {
            returnvec <- c(returnvec,vec[seq(n)])
        } else if(pad) {
            returnvec <- c(returnvec,rep(NA,n))
        }
    } else if(n<0) {
        returnvec <- vec[seq(1,length(vec)-abs(n))]
        if(wrap) {
            returnvec <- c( vec[seq(length(vec)-abs(n)+1,length(vec))], returnvec )
        } else if(pad) {
            returnvec <- c( rep(NA,abs(n)), returnvec )
        }

    }
    return(returnvec)
}

最重要的是对现有类的扩展,这些扩展在其他任何地方都找不到(例如,用于格子图的CDF面板函数,各种xtable和LaTeX输出函数,用于在地理空间对象类型之间进行处理和转换以及执行各种GIS-像叠加等操作).

The most important are extensions to existing classes that can't be found anywhere else (e.g. a CDF panel function for lattice plots, various xtable and LaTeX output functions, classes for handling and converting between geospatial object types and performing various GIS-like operations such as overlays).

我想以R形式在Internet上的某个地方提供这些内容(例如,将它们作为纯文本功能发布到博客中不是我想要的),这样维护起来更加容易,因此我和其他人可以从我访问的任何计算机上访问它们.逻辑上的事情是用它们制作一个程序包,然后将它们发布到CRAN中-实际上我已经将它们打包了.但是,这些功能集合是否适合CRAN软件包?

I would like to make these available somewhere on the internet in R-ized form (e.g. posting them on a blog as plain text functions is not what I'm looking for), so that maintenance is easier and so that I and others can access them from any computer that I go to. The logical thing to do is to make a package out of them and post them to CRAN--and indeed I already have them packaged up. But is this collection of functions suitable for a CRAN package?

我有两个主要问题:

  1. 函数似乎没有任何连贯的叠加层.只是一个 做许多不同事情的功能的集合.
  2. 我的代码并不总是最漂亮.我试着清理它 学习了更好的编码实践,但产生了R核心价值的美丽 卡中没有密码.
  1. The functions don't seem to have any coherent overlay. It's just a collection of functions that do lots of different things.
  2. My code isn't always the prettiest. I've tried to clean it up as I learned better coding practices, but producing R Core-worthy beautiful code is not in the cards.

CRAN网页出人意料地失去了发布指南.考虑到某些人会发现它有用,但从某种意义上说它将永远锁定R使其占用一些非常基本的函数名,因此我应该发布到CRAN上吗?还是有另一个地方可以使用类似install.packages的命令进行安装?请注意,我宁愿避免将软件包发布到网页上,而要让人们记住要安装软件包的URL(尤其是版本控制问题).

The CRAN webpage is surprisingly bereft of guidelines on posting. Should I post to CRAN, given that some people will find it useful but that it will in some sense forever lock R into having some pretty basic function names taken up? Or is there another place I can use an install.packages-like command to install from? Note I'd rather avoid posting the package to a webpage and having people have to memorize the URL to install the package (not least for version control issues).

推荐答案

大多数软件包应该是具有明显目的的相关函数的集合,因此要做的一件有用的事情是尝试将所拥有的东西归为一组,然后查看是否您可以对它们进行分类.几个较小的程序包比一个庞大的不相关程序包要好.

Most packages should be collections of related functions with an obvious purpose, so a useful thing to do would be to try and group what you have together, and see if you can classify them. Several smaller packages are better than one huge incoherent package.

也就是说,有些软件包是杂项实用程序功能的集合,其中最著名的是Hmiscgregmisc,所以可以做这种事情.如果您只有一些这样的功能,可能值得联系一些杂项软件包的作者,看看它们是否会让您将代码包括在其软件包中.

That said, there are some packages that are collections of miscellaneous utility functions, most notably Hmisc and gregmisc, so it is okay to do that sort of thing. If you just have a few functions like that, it might be worth contacting the author of some of the misc packages and seeing if they'll let you include your code in their package.

对于编写漂亮的代码,您可以做的最重要的事情是使用样式指南.

As for writing pretty code, the most important thing you can do is to use a style guide.

这篇关于不完善但有用的功能怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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