Re: [R] Parser For Line Number Tracing

2025-01-18 Thread Iris Simmons
as needed. Regards, Iris On Sat, Jan 18, 2025 at 6:41 PM Ivo Welch wrote: > > I often find myself hunting where in my program an error has happened, > (of course, in R, many error messages are mysterious in themselves, > too, making it even harder.) the way I do it is

Re: [R] Extracting specific arguments from "..."

2025-01-05 Thread Iris Simmons
I would use two because it does not force the evaluation of the other arguments in the ... list. On Sun, Jan 5, 2025, 13:00 Bert Gunter wrote: > Consider: > > f1 <- function(...){ > one <- list(...)[['a']] > two <- ...elt(match('a', ...names())) > c(one, two) > } > ## Here "..." is an ar

Re: [R] outer() is not working with my simple function

2024-12-10 Thread Iris Simmons
outer() expects a return value with the same length as that of x. You could change the code to rep(3, length(x)) Or if you don't want to change the code of the function, you could make a wrapper and use that instead: function (x, y) { v <- FN1(x, y) if (length(v) != 1) v else rep(v, lengt

Re: [R] readLines() and unz() and non-empty final line

2024-10-25 Thread Iris Simmons
compatibility or 'blocking = TRUE' for consistency with 'file()'. Regards, Iris On Fri, Oct 25, 2024, 04:47 Marttila Mikko wrote: > Thanks Iris, Bert, and Tim. > > > > Whether unz() is blocking or not by default doesn’t seem to be documented. > Indeed, tha

Re: [R] readLines() and unz() and non-empty final line

2024-10-24 Thread Iris Simmons
Hi Mikko, I tried running a few different things, and it seems as though explicitly using `open()` and opening a blocking connection works. ```R cat("hello", file = "hello.txt") zip("hello.zip", "hello.txt") local({ conn <- unz("hello.zip", "hello.txt") on.exit(close(conn)) ## you ca

Re: [R] Reading a txt file from internet

2024-09-07 Thread Iris Simmons
That looks like a UTF-16LE byte order mark. Simply open the connection with the proper encoding: read.delim( 'https://online.stat.psu.edu/onlinecourses/sites/stat501/files/ch15/employee.txt', fileEncoding = "UTF-16LE" ) On Sat, Sep 7, 2024 at 3:57 PM Christofer Bogaso wrote: > > Hi, > >

Re: [R] grep

2024-08-01 Thread Iris Simmons
You can find more by reading through ?regex as well as Perl documentation (which you can find online). On Thu, Aug 1, 2024, 21:11 Steven Yen wrote: > Good Morning. Below I like statement like > > j<-grep(".r\\b",colnames(mydata),value=TRUE); j > > with the \\b option which I read long time ago w

Re: [R] Using the pipe, |>, syntax with "names<-"

2024-07-20 Thread Iris Simmons
It should be written more like this: ```R z <- data.frame(a = 1:3, b = letters[1:3]) z |> names() |> _[2] <- "foo" z ``` Regards, Iris On Sat, Jul 20, 2024 at 4:47 PM Bert Gunter wrote: > > With further fooling around, I realized that explicitly assigning my &g

Re: [R] I have Problem using the Pipe Command

2024-06-18 Thread Iris Simmons
My guess would be that you're using an older version of R. The pipe was added in R 4.1. It cannot be used in earlier versions as the syntax is invalid. You could use the dplyr pipe if you want further back compatibility. On Tue, Jun 18, 2024, 12:14 Ogbos Okike wrote: > Greetings to everyone and

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. >

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: https://github.com/wch/r-source/blob/04650eddd6d844963b6d7aac

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 wrote:

Re: [R] Problem with R coding

2024-03-12 Thread Iris Simmons
, > writeLines(utils::shortPathName(r"(C:\Users\iris\OneDrive - Organization Name Non ASCII\Documents)")) C:\Users\iris\ONEDRI~1\DOCUME~1 and then in the control panel, then user accounts (twice), then Change My Environment Variables, enter the variable name HOME and the directory that was

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 about

Re: [R] Capturing Function Arguments

2024-02-18 Thread Iris Simmons
``` > f0 <- function(x, y = 2 * z, z, a = NULL, b) NULL > a <- 1 > x <- f(a, z = 1 + 100) > x$args2 $x [1] 1 $y [1] 202 $z [1] 101 $a NULL $b > ``` Regards, Iris On Sun, Feb 18, 2024 at 3:51 AM Reed A. Cartwright wrote: > > I'm wrapping a function in R a

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

2023-11-12 Thread Iris Simmons
uncan 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, > >> > >> &

[R] Calling Emacs Lisp Code/Function from R

2023-11-10 Thread Iris Simmons
function from R, or if that's not possible then calling it from C would be fine. Does anyone know if this is possible? And if so, could you perhaps direct me towards an existing R package or program that calls an Emacs Lisp function from R that I could use as a gui

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, eval(b

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] 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, basi

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 pro

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

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

2023-08-15 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] 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 1

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" > ```

[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 directives

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] 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 names,

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

2023-04-19 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 (fai

Re: [R] Save rgl plot3d Graph as Image

2012-06-26 Thread iris
In the rgl package *rgl.postscript *can save 3d scatter plots you have generated using the plot3d command . For example open3d() x <- sort(rnorm(1000)) y <- rnorm(1000) z <- rnorm(1000) + atan2(x,y) plot3d(x, y, z, col=rainbow(1000)) rgl.postscript("persp3dd.pdf","pdf") -- View this mess

Re: [R] kinship package: drawing pedigree error

2008-02-07 Thread Iris Kolder
I tried replacing the missing parents with 0 but got the same error Error in if (min(pos2) < 0) { : missing value where TRUE/FALSE needed Any other thoughts? Iris Subject: Re: [R] kinship package: drawing pedigree error On Wed, 06-Feb-2008 at 04:49AM -0800, Iris Kolder wr

[R] kinship package: drawing pedigree error

2008-02-06 Thread Iris Kolder
,1,0 I tried putting nuclear families closer together in de pedigree but this doesn't seem to help. All individuals have both parents in the pedigree or have 2 missing parents. I hope someone can help me with this! Iris _

Re: [R] Matching and merging two rows with missing values

2007-10-11 Thread Iris Kolder
he output i want is one row 1 2 3 4 5 Row AA AG GG AA NA I tried to use the functions match,grep, and gsub but I can't seem to make it work I would appreciate any suggestions! Best regards, Iris Kolder [[alternative HTML version deleted]] _

[R] Matching and merging two rows with missing values

2007-10-11 Thread Iris Kolder
e any suggestions! Best regards, Iris Kolder [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htm