[R] How to keep the command 'R CMD INSTALL -l' running, even when some error is encountered?

2011-08-22 Thread thmsfuller...@gmail.com
Hi, 'R CMD INSTALL -l' will stop if some error is encountered. I don't find in the manual an option to keep the command running. Is there such an option? -- Tom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE d

Re: [R] enclosing with() in a function

2011-08-08 Thread thmsfuller...@gmail.com
a, elem_name) { >>   mean(data[[elem_name]]) >> } >> mean_on_element(data, 'x') >> >> Since 'x' is quoted in the function call, you need to use code that >> can convert the string 'x' to extracting the data object with name x. >&

Re: [R] enclosing with() in a function

2011-08-08 Thread thmsfuller...@gmail.com
my_sum(data, c('x1', 'x3', 'x6')) >> >> # (2) Lose 'with' and use subscripting instead: >> mean_on_element=function(data, elem_name) { >>   mean(data[[elem_name]]) >> } >> mean_on_element(data, 'x') >> >&g

[R] enclosing with() in a function

2011-08-08 Thread thmsfuller...@gmail.com
Hi All, I want to enclose with() in a function mean_on_element. Obviously, it is not working. The problem is how to specify the element name with a function body. Does anybody have any suggestion? Thanks! > data=list(x=1:10) > with(data, mean(x)) [1] 5.5 > > mean_on_element=function(data, elem_na

[R] How to get the names of all the packages that depend on a give package?

2011-04-13 Thread thmsfuller...@gmail.com
Dear All, I want to check what packages depends on a given package. For example, glmnet depends on Matrix. I want get the names of all the packages that depend on Matrix on CRAN. Is there a way to do so? Thanks! > library(glmnet) Loading required package: Matrix Loading required package: lattice

[R] How to execute an expression as well as a .R file with Rscript?

2010-08-19 Thread thmsfuller...@gmail.com
Hello All, I'm trying to supply both an expression and a .R file to Rscript. But it seems that it is not possible with the first approach (see below) and I'll have to use the second approach (see below). I'm wondering if it is a bug in Rscript not to support both a .R file and an expression. $ ca

[R] Disable options(echo=T) that was set in .Rprofile without showing anything to the screen

2010-08-02 Thread thmsfuller...@gmail.com
Hello All, I have the following line and some other lines in my .Rprofile. options(echo=T) To disable it, I have the following in the first line in the script. But 'Rscript a_script.R' still shows ">options(echo=F)", which I want to get rid of it as well. options(echo=F) I tried to use the fol

[R] Why do the results of paste() depend on how the argument (data.frame) is constructed?

2010-08-01 Thread thmsfuller...@gmail.com
Hi, The following two 'df's should be the same, although their constructions are different. But the results of paste() are different. I don't see this is explained in ?paste. Could you help me understand why it is like this? > df=data.frame(X=c(1, 2, 3), Y=c(4, 5, 6)) > df X Y 1 1 4 2 2 5 3 3 6

[R] Permutation of a sequence to without changing local distribution

2010-08-01 Thread thmsfuller...@gmail.com
Hello All, Suppose that I have a sequence of letters (e.g., A..Z). I want to permute the sequence to generate random sequences, such that the local density of any letter with a window (say of length L) doesn't change much before and after permutation. One way that I can thing of is to require tha

[R] Set environment name

2010-07-13 Thread thmsfuller...@gmail.com
Hello All, ?environmentName shows how to get the environment name. But I don't see how to set the name in the first place. Could you tell me where to look for the function that set the environment name? -- Tom __ R-help@r-project.org mailing list http

[R] How to define a function (with '<-') that has two arguments?

2010-07-13 Thread thmsfuller...@gmail.com
Hi All, The last line if the following code returns the error right below this paragraph. Essentially, I use the operator %:% to retrieve a variable in a nested frame. Then I want to use the same operator (with '<-') to change its value. I'm not sure if this is possible in R with %:% operator. Wo

[R] Rename column or row names

2010-07-13 Thread thmsfuller...@gmail.com
Hello All, Suppose that x is a data.frame. I want to change the colname 'oldname' to 'newname'. I have the following code. Could anybody let me know if there is any better way to change a column name? colnames(x)[grep('oldname', colnames(x))]='newname' -- Tom __

[R] Why Rscript behaves strangely with file name starting with 'size'?

2010-07-07 Thread thmsfuller...@gmail.com
Hello All, It seems weird to me that Rscript does the following thing and enters the R prompt mode. If I change the file name to something that doesn't start with 'size', then Rscript runs normally. Does anybody know what is going on? $ Rscript size.R WARNING: '--file=size.R' value is invalid: ig

[R] What does `_data` mean in transform()?

2010-07-07 Thread thmsfuller...@gmail.com
Hi All, I meant to take the min row by row. But the result is apparently not what I want. Changing min to pmin solve the problem. > df=data.frame(X=1:10, Y=1:10) > transform(df, Z=min(X,10-Y)) X Y Z 1 1 1 0 2 2 2 0 3 3 3 0 4 4 4 0 5 5 5 0 6 6 6 0 7 7 7 0 8 8 8 0 9 9

[R] Weired problem when passing arguments using ...?

2010-07-07 Thread thmsfuller...@gmail.com
Hello All, I'm trying to pass the argument col.names to write.csv using '...'. But I got the following warnings. Maybe it is very simple. But I'm not sure what I am wrong. Could you please help point to me what the problem is? # fun=function(x, ...) { fr=parent.frame() tm

[R] How not to print '\\' as '\\'

2010-07-06 Thread thmsfuller...@gmail.com
Hello All, '\\' is printed as '\\', but it is actually only one character. Sometimes, I'd rather print it as a single '\'. Is there a function to do so in R? > nchar('\\') [1] 1 > print('\\') [1] "\\" -- Tom __ R-help@r-project.org mailing list https

[R] How to get the definition of a function if it is masked by a variable?

2010-05-28 Thread thmsfuller...@gmail.com
Hello, Normally, if I type a function name, it shows the function definition. When the function is masked by a variable with the same name, it doesn't show the function definition any more. Can anyone please tell me a way how to retrieve the function definition even if it is masked by a variable?

[R] How sample without replacement on more than one variables?

2010-05-23 Thread thmsfuller...@gmail.com
Hello All, sample() only sample on one variable x. But I'm interested in sampling more than one variable without replacement. Suppose I have 3 vectors x, y, z. I want to draw samples from all three vectors such that the combination of the three elements in each draw is not the same as any previou