English 中文(简体)
Rscript vs source: 关键差别是什么?
原标题:Rscript vs. source: What are the key differences?
  • 时间:2011-10-16 01:58:06
  •  标签:
  • r

This might be a very basic question, but have not found a convincing answer yet. When executing an R script within the R environment, I can either do source(foo.R) or system("Rscript foo.R"). Is there any difference at all between the two approaches, and if so how do the two approaches compare?

最佳回答

它们的影响基本不同。

  • <条码>源(“foo.R”) 指: R process to take its observations from < code>"foo.R" .

  • system(“Rscript foo.R”>> 使用操作系统指令发射separate R process, within which the content of "foo.R" are evaluation.

www.un.org/Depts/DGACM/index_french.htm 电话只直接影响到本届会议,除外,否则,它将在你目前的任期内印刷该届R会议的产出。 (你可以在<条码>系统中()打电话,设定<条码>show.output.on.console=FALSE。)

问题回答

I think source(foo.R) includes the source code of that file (foo.R) into your current environment. If you define a variable within foo.R, let s say x <- 5, and in your current project you define x <- 6 beforehand, x becomes 5.

system(“Rscript foo.R”>>, 随附理由/foo.R,因此,你目前的环境根本不受影响。

作为对@Ramnath评论的答复:sys.source(“foo”)不相同。 Rscript foo。 例如,你可使用<编码>sys.source:

e <- new.env()
sys.source("foo", e)  # foo creates a bunch of objects in environment e
z <- with(e, {
    # do stuff with e....
})
rm(e)

如果你正在制造几个中间物体,你会这样做,而后,这些物体就会 st,最后结果会回来。 你们不想保留中间物体,这样就把物体放在自己的临时环境中,就是一个轻而易举的办法。





相关问题
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 ...

热门标签