English 中文(简体)
A. 在R编订成套材料时采用以往版本的功能
原标题:Purging previous versions of functions when developing packages in R
  • 时间:2012-04-30 15:10:50
  •  标签:
  • r
  • package

我正在R中拟定一揽子计划。 请打电话mypkg

由于有些职能在从一揽子计划(我无法确定为什么不是问题)运作时有不同的做法,我正在编辑一揽子计划的职能,然后从指挥线重建一揽子计划。 由于某种原因,某一审案保留了较旧的职能,尽管来文方已经改变,而且一揽子计划已经重建和重新安装。 我需要开一个新例子,看看这些变化。

这里是典型的工作流程。

  1. Make changes to myfunction() in mypkg.R
  2. In R: detach(package:mypkg); remove.packages("mypkg")
  3. Command line: R CMD INSTALL --build c:mypkg
  4. Notifies me that it has been installed to the default library
  5. In R: library(mypkg)
  6. In R: myfunction() runs the previous version before changes.

[The next three steps I want to avoid]

  1. Start a new R instance
  2. In R: library(mypkg)
  3. myfunction() works as expected

R.2.14.1.

I am looking for suggestions of how to improve this workflow to avoid starting a new R instance.

最佳回答

你们需要努力卸载包件并拆除包件。 ?detach :

If a package has a namespace, detaching it does not by default unload the namespace (and may not even with ‘unload=TRUE’), and detaching will not in general unload any dynamically loaded compiled code (DLLs). Further, registered S3 methods from the namespace will not be removed. If you use ‘library’ on a package whose namespace is loaded, it attaches the exports of the already loaded namespace. So detaching and re-attaching a package may not refresh some or all components of the package, and is inadvisable.

Note the last sentence in particular.

Try:

detach(package:mypkg, unload = TRUE)

请注意,“如果一揽子计划有一个名称空间”,现在是指所有包裹,因为R 2.14.0(IIRC, 版本编号)的改动。

如果您的代码为R代码,则考虑使用assignInNamespace()在您的全球工作空间(即mypkg的新功能版本)指定为mypkg。 例如,我们在以下地方有职能:foo(),mypkg;我们在当地有newfoo(,即foo(>)的新版本:

assignInNamespace("foo", newfoo, "mypkg")

如果这些改动与《刑法》有关,或与上述规定无关,那么你或许应当遵循R Core的建议,并开创一个新的审案,而不是试图抹去你的包裹。

另见Hadley Wickham和Emacs+ESS的devtools一揽子计划,如果你讲Emacs的话,可能会使发展进程更加容易(报道新的R事例等)。

问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签