Re: [R] How to Reformat a dataframe

2023-10-27 Thread Iris Simmons
You are not getting the structure you want because the indexes are wrong. They should be something more like this: i <- 0 for (row in 1:nrow(alajuela_df)){ for (col in 1:ncol(alajuela_df)){ i <- i + 1 df[i,1]=alajuela_df[row,col] } } but I think what you are doing can be written much

Re: [R] Dynamically create a (convenience) function in a package

2023-10-30 Thread Iris Simmons
If you don't know the name of the attributes in advance, how can you know the function name to be able to call it? This seems like a very flawed approach. Also, I would discourage the use of eval(parse(text = )), it's almost always not the right way to do what you want to do. In your case,

Re: [R] Bug in print for data frames?

2023-10-26 Thread Iris Simmons
I would say this is not an error, but I think what you wrote isn't what you intended to do anyway. y[1] is a data.frame which contains only the first column of y, which you assign to x$C, so now x$C is a data.frame. R allows data.frame to be plain vectors as well as matrices and data.frames,

Re: [R] Create a call but evaluate only some elements

2023-10-25 Thread Iris Simmons
You can try either of these: expr <- bquote(lm(.(as.formula(mod)), dat)) lm_out5 <- eval(expr) expr <- call("lm", as.formula(mod), as.symbol("dat")) lm_out6 <- eval(expr) but bquote is usually easier and good enough. On Wed, Oct 25, 2023, 05:10 Shu Fai Cheung wrote: > Hi All, > > I have a

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-16 Thread Iris Simmons
You could rewrite 1 - cos(x) as 2 * sin(x/2)^2 and that might give you more precision? On Wed, Aug 16, 2023, 01:50 Leonard Mada via R-help wrote: > Dear R-Users, > > I tried to compute the following limit: > x = 1E-3; > (-log(1 - cos(x)) - 1/(cos(x)-1)) / 2 - 1/(x^2) + log(x) > # 0.4299226

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-16 Thread Iris Simmons
You might also be able to rewrite log(1 - cos(x)) as log1p(-cos(x)) On Wed, Aug 16, 2023, 02:51 Iris Simmons wrote: > You could rewrite > > 1 - cos(x) > > as > > 2 * sin(x/2)^2 > > and that might give you more precision? > > On Wed, Aug 16, 2023, 01:50

[R] Calling Emacs Lisp Code/Function from R

2023-11-10 Thread Iris Simmons
Hi, I'm using R in Emacs and I'm interested in programatically knowing the details of all opened buffers; details such a buffer name, size, mode, and possibly associated filename. I've been able to write such a function in Emacs Lisp, but now I'd like to be able to call that function from R, or

Re: [R] running a function repeatedly on error....

2023-04-20 Thread Iris Simmons
I might try something like this: FUN1 <- function () { threshold <- 4L fails <- 0L internal <- function() { ## do the actual downloading here tryCatch({ download.file(<...>) }, error = function() { fails <<- fails + 1L if

Re: [R] extract parts of a list before symbol

2023-05-26 Thread Iris Simmons
You probably want `names(test)`. On Thu, May 25, 2023 at 7:58 PM Evan Cooch wrote: > Suppose I have the following list: > > test <- list(a=3,b=5,c=11) > > I'm trying to figure out how to extract the characters to the left of > the equal sign (i.e., I want to extract a list of the variable

Re: [R] environments: functions within functions

2023-05-26 Thread Iris Simmons
Hi, I think there are two easy ways to fix this. The first is to use a `switch` to call the intended function, this should not be a problem since there are a small number of print functions in **mixR** ```R print.mixfitEM <- function (x, digits = getOption("digits"), ...) { switch(x$family,

Re: [R] Stacking matrix columns

2023-08-05 Thread Iris Simmons
You could also do dim(x) <- c(length(x), 1) On Sat, Aug 5, 2023, 20:12 Steven Yen wrote: > I wish to stack columns of a matrix into one column. The following > matrix command does it. Any other ways? Thanks. > > > x<-matrix(1:20,5,4) > > x > [,1] [,2] [,3] [,4] > [1,]16 11

[R] Line Directives in Sweave Document

2023-06-28 Thread Iris Simmons
Hello, I'm trying to demonstrate the behaviour of my R package and how line directives change that behaviour. So I've got an R chunk like this: <>= { #line 1 "file1.R" fun <- function() { pkg::fun() } #line 1 "file2.R" fun() } @ but when it is rendered, the line

Re: [R] replacing unicode characters

2023-06-28 Thread Iris Simmons
Hiya! You can do this by specifying sub="c99" instead of "Unicode": ```R x <- "fa\xE7ile" xx <- iconv(x, "latin1", "UTF-8") iconv(xx, "UTF-8", "ASCII", "c99") ``` produces: ``` > x <- "fa\xE7ile" > xx <- iconv(x, "latin1", "UTF-8") > iconv(xx, "UTF-8", "ASCII", "c99") [1] "fa\\u00e7ile" > ```

Re: [R] Capturing Function Arguments

2024-02-18 Thread Iris Simmons
Hi Reed, I need to stress before giving my answer that no solution can handle everything. These scenarios will always lead to problems: * if any of the formal arguments rely on the current state of the call stack * if any of the formal arguments rely on a variable that is only defined later in

Re: [R] Calling Emacs Lisp Code/Function from R

2023-11-12 Thread Iris Simmons
Murdoch wrote: > > I'm not an Emacs user, but the ESS-help mailing list (see > > ess.r-project.org) might be able to help with this. > > > > Duncan Murdoch > > > > On 10/11/2023 3:43 a.m., Iris Simmons wrote: > >> Hi, > >> > >> > >&g

Re: [R] gsub issue with consecutive pattern finds

2024-03-01 Thread Iris Simmons
Hi Iago, This is not a bug. It is expected. Patterns may not overlap. However, there is a way to get the result you want using perl: ```R gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) ``` The specific change I made is called a positive lookahead, you can read more

Re: [R] Problem with R coding

2024-03-12 Thread Iris Simmons
Hi Maria, I had something similar on my Windows work laptop at some point where the home directory was something containing non ASCII characters. The easy solution is to copy said directly from the file explorer into utils::shortPathName, and then set that as the home directory. In my case, >

Re: [R] as.complex()

2024-03-25 Thread Iris Simmons
Hi Thomas, If you want to compare the imaginary portions, you could do: Im(z1) < Im(z2) If you want to compare the magnitudes, you could do: Mod(z1) < Mod(z2) If you want to compare complex numbers, i.e. z1 < z2, well that just doesn't make sense. On Mon, Mar 25, 2024, 10:17 Thomas K

Re: [R] Regexp pattern but fixed replacement?

2024-04-11 Thread Iris Simmons
Hi Duncan, I only know about sub() and gsub(). There is no way to have pattern be a regular expression and replacement be a fixed string. Backslash is the only special character in replacement. If you need a reference, see this file:

Re: [R] strange behavior in base::as.double

2024-05-01 Thread Iris Simmons
This happens because "123e" looks like exponential form. This string has no exponent, so it gets treated as 0 exponent. If you're interested in converting hex numbers, append 0x: as.numeric("0x123a") or use strtoi: strtoi("123a", 16) On Wed, May 1, 2024, 15:24 Carl Witthoft wrote: > Hello.