[R] Documentation of Trigonometric Functions.

2021-04-14 Thread Jorgen Harmse via R-help
Is correct but incomplete documentation considered a bug? The documentation of trigonometric functions goes into detail about branch cuts for asin etc., but does not discuss the discontinuities of atan2. (It also fails to explain the difference between asin(2) (NaN) and asin(2+0i) (pi/2-acosh(2)

Re: [R] assumptions about how things are done

2021-10-11 Thread Jorgen Harmse via R-help
As noted by Richard O'Keefe, what usually happens in an R function is that any argument is evaluated either in its entirety or not at all. A few functions use substitute or similar trickery, but then expectations should be documented. I can understand that you want something like ifelse(y>x,x/y,

Re: [R] names.data.frame?

2021-11-04 Thread Jorgen Harmse via R-help
Can someone please explain what Leonard Mada is trying to do? As far as I know, names is not generic and there is no names.data.frame because it’s not needed. (A data.frame seems to be just a named list with some extra functionality that depends on every element being a vector with the same leng

Re: [R] Bug in list.files(full.names=T)

2021-12-20 Thread Jorgen Harmse via R-help
There is a possibly related problem in file.path. As Murdoch says, it's ugly even if the OS accepts it, and I don't see that the base version is any better than paste(sep=fsep, ...). Pasting the result into emacs wouldn't work. I wrote my own version to remove trailing fsep from all but the last

Re: [R] How important is set.seed

2022-03-22 Thread Jorgen Harmse via R-help
Jeff Newmiller makes an interesting point about distributed processing, but I don�t know how to use the usual pseudo-random processes to obtain deterministic results when I don�t know how the data will be sharded. You might have to replace pseudo-random sampling with deterministic sampling using

Re: [R] Question about Line Ending Choice

2022-09-28 Thread Jorgen Harmse via R-help
eol seems to be the parameter to use, but the answers so far appear to assume that the file is created on a Mac. For example, I think that �\r\n� on Windows would produce CR CR LF. I don�t have both systems handy (so I can�t test), but I think you should use raw to specify the bytes you want. #

Re: [R] unexpected 'else' in " else"

2022-10-21 Thread Jorgen Harmse via R-help
Andrew Simmons is correct but doesn't explain why the code works in the package. This is one of only two differences I have found between running code at the command line and running it from a file. (The other difference is that code in a file is often executed in an environment other than .Glob

Re: [R] [EXTERNAL] Re: unexpected 'else' in " else"

2022-10-21 Thread Jorgen Harmse via R-help
parenthesis (or possibly brackets) will continue looking for `else` even after `cons.expr` and a newline has been fully parsed, but will not otherwise. On Fri, Oct 21, 2022 at 10:39 AM Jorgen Harmse via R-help wrote: > > Andrew Simmons is correct but doesn't explain why the code works

Re: [R] unexpected 'else' in " else" (Ebert,Timothy Aaron)

2022-10-24 Thread Jorgen Harmse via R-help
There were several interesting points about `ifelse`. The usual behaviour seems to be that all three inputs are evaluated, and the entries of `yes` corresponding to `TRUE` in `test` are combined with the entries of `no` corresponding to `FALSE` in `test`. Moreover, `yes` & `no` seem to be recycl

Re: [R] [EXTERNAL] Re: unexpected 'else' in " else" (Ebert, Timothy Aaron)

2022-10-24 Thread Jorgen Harmse via R-help
I agree that the documentation should be clarified. Moreover, my last example shows that the class can be different even when no mode coercion is required. I don't know enough about S3 & S4 to comment on your last point. Regards, Jorgen Harmse. From: Bert Gunter Date: Monday, 24October, 2022

Re: [R] [EXTERNAL] Re: unexpected 'else' in " else" (Ebert, Timothy Aaron)

2022-10-25 Thread Jorgen Harmse via R-help
Good catch! I also misread it, and I think most people would. If I wanted to write confusing documentation then I could play similar games with 'mode' and 'length'. Regards, Jorgen Harmse. > test <- c(TRUE,FALSE,FALSE) > attr(test,'class') <- 'foo' # probably a bad idea, but I want to see wh

Re: [R] unexpected 'else' in " else"

2022-10-28 Thread Jorgen Harmse via R-help
Richard O'Keefe's remarks on the workings of the interpreter are correct, but the code examples are ugly and hard to read. (On the other hand, anyone who has used the debugger may be de-sensitised to horrible code formatting.) The use of whitespace should if possible reflect the structure of the

Re: [R] [EXTERNAL] RE: unexpected 'else' in " else"

2022-10-28 Thread Jorgen Harmse via R-help
: unexpected 'else' in " else" I appreciate this thread on coding. My preference for reading is to have complete sentences. I can read this: { if (x On Behalf Of Jorgen Harmse via R-help Sent: Friday, October 28, 2022 10:39 AM To: r-help@r-project.org Subject: Re: [R] unexpected 'el

Re: [R] Get data from a list of data frames (Stefano Sofia)

2022-12-16 Thread Jorgen Harmse via R-help
Following Bert Gunter's suggestion, I wonder why the data are in separate frames (with hard-coded values) in the first place. You could put them in a text file and call read.table. If you provide a header and put a meaningful station name at the start of each data row then rownames of your data

Re: [R] function doesn't exists but still runs..... (akshay kulkarni)

2023-01-20 Thread Jorgen Harmse via R-help
It may help to expand a bit on Bill Dunlap's answer. I think that library does something like this: Create a new environment for all the package objects. This environment will not be directly visible from .GlobalEnv, and ancestor environments may not be directly visible either. It may contain

Re: [R] [EXTERNAL] Re: function doesn't exists but still runs..... (akshay kulkarni)

2023-01-20 Thread Jorgen Harmse via R-help
Hi Akshay, Lexical scoping and environments are closely tied. (I think Bill even cited the documentation.) I guess it's arcane in the sense that scoping usually does what you expect, but the way that works is related to what we discussed. What led you to discover the issue? Were you debugging t

Re: [R] [EXTERNAL] Re: function doesn't exists but still runs..... (akshay kulkarni)

2023-01-23 Thread Jorgen Harmse via R-help
Hi Akshay, I usually use debug (a function provided by R). When you are stepping through a function your environment is the one in which function code is being executed, so you can easily see everything that is visible to the function. If you single step into a function that the first function

Re: [R] preserve class in apply function

2023-02-08 Thread Jorgen Harmse via R-help
What are you trying to do? Why use apply when there is already a vector addition operation? df$x+df$y or as.numeric(df$x)+as.numeric(df$y) or rowSums(as.numeric(df[c('x','y')])). As noted in other answers, apply will coerce your data frame to a matrix, and all entries of a matrix must have the

Re: [R] Could you manually replicate execution of a R function

2023-09-20 Thread Jorgen Harmse via R-help
There may be collisions between variables in .GlobalEnv and variables in the function-call environment, and the parent of the function-call environment probably includes functions & other variables not available in .GlobalEnv. (If the function calls substitute or anything like that then the prob

Re: [R] save(), load(), saveRDS(), and readRDS()

2023-09-29 Thread Jorgen Harmse via R-help
Ivan Krylov points out that load(file, e <- new.env()) is cumbersome. I put it into a function. Regards, Jorgen Harmse. #' Save & load lists & environments #' #' \code{\link{save}} has to be told what to save from an environment, and the obvious way #' to save a structure creates an extra l

Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread Jorgen Harmse via R-help
df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG)) That will do both calculations and merge the two vectors appropriately. It will use extra memory, but it should be much faster than a 'for' loop. Regards, Jorgen Harmse. -- Message: 8 Date: Fri, 3 Nov 202

Re: [R] [EXTERNAL] RE: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-03 Thread Jorgen Harmse via R-help
. Just a minor point in the suggested solution: df$LAP <- with(df, ifelse(G=='male', (WC-65)*TG, (WC-58)*TG)) since WC and TG are not conditional, would this be a slight improvement? df$LAP <- with(df, TG*(WC - ifelse(G=='male', 65, 58))) -Original Message- From

Re: [R] [EXTERNAL] Re: I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-06 Thread Jorgen Harmse via R-help
That�s ingenious, but I would hesitate to rely on a specific mapping between strings and integers. (I usually read data frames with stringsAsFactors=FALSE or coerce to character later: I don�t think it takes more memory.) Maybe create another column with the coefficients. What if gender is part

Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category

2023-11-06 Thread Jorgen Harmse via R-help
Avi: Thank you for checking. I think the optimization is limited. If test is all TRUE or all FALSE then at most one vector is evaluated. Anything beyond that would be very complicated. (Inspect the two expressions and verify that both specify elementwise computations. Then use indexing to shrink

[R] Building Packages.

2024-03-20 Thread Jorgen Harmse via R-help
I have a source file with oxygen-style comments (and description & licence files), and I’m trying to build a package. oxygen & devtools seem to work, and the tarball exists, but install.packages balks. Does anyone know what’s happening? Regards, Jorgen Harmse. > roxygenise(package.dir,clean=T

Re: [R] Building Packages.

2024-03-20 Thread Jorgen Harmse via R-help
From: Ivan Krylov Date: Wednesday, March 20, 2024 at 11:14 To: Jorgen Harmse via R-help Cc: Jorgen Harmse Subject: [EXTERNAL] Re: [R] Building Packages. � Wed, 20 Mar 2024 16:02:27 + Jorgen Harmse via R-help �: > > install.packages(tar,type='source',repos=NULL) >

Re: [R] Building Packages.

2024-03-20 Thread Jorgen Harmse via R-help
x27;width')} #' #' @export width <- function(dw) options(width = options('width')[[1L]] + as.integer(dw)) From: Duncan Murdoch Date: Wednesday, March 20, 2024 at 12:09 To: Jorgen Harmse , Ivan Krylov , Jorgen Harmse via R-help Subject: [EXTERNAL] Re: [R] Buildi

Re: [R] Building Packages.

2024-03-20 Thread Jorgen Harmse via R-help
urce) ) file.copy(DESC.source, file.path(package.dir,"DESCRIPTION"), overwrite=TRUE) roxygenise(package.dir,clean=clean) tar <- devtools::build(package.dir) if (install) install.packages(tar,type='source',repos=NULL) invisible() } From: Ivan Krylov Date:

Re: [R] Building Packages.

2024-03-21 Thread Jorgen Harmse via R-help
> Turns out that RStudio replaces the install.packages object in the utils > package. > Duncan Murdoch So RStudio unlocks the bindings and alters the exported environment? That seems like another reason to stick to the terminal interface. >> Thank you. tools:::.install_packages works. > I'm gl

Re: [R] duplicated() on zero-column data frames returns empty

2024-04-05 Thread Jorgen Harmse via R-help
(I do not know how to make Outlook send plain text, so I avoid apostrophes.) For what it is worth, I agree with Mark Webster. The discussion by Ivan Krylov is interesting, but if duplicated really treated a row name as part of the row then any(duplicated(data.frame(�))) would always be FALSE. My

Re: [R] duplicated() on zero-column data frames returns empty

2024-04-08 Thread Jorgen Harmse via R-help
I appreciate the compliment from Ivan and still share the puzzlement at the empty return. What is the policy for changing something that is wrong? There is a trade-off between breaking old code that worked around a problem and breaking new code written by people who make reasonable assumptions.

Re: [R] [EXTERNAL] Re: duplicated() on zero-column data frames returns empty

2024-05-13 Thread Jorgen Harmse via R-help
Good luck! It looks like a significant effort for someone not already on the team. Regards, Jorgen Harmse. From: Mark Webster Date: Monday, May 13, 2024 at 04:07 To: Jorgen Harmse , Ivan Krylov Cc: r-help@r-project.org Subject: [EXTERNAL] Re: duplicated() on zero-column data frames returns em

Re: [R] Listing folders on One Drive

2024-05-21 Thread Jorgen Harmse via R-help
I would just use fi <- file.info(dir(path, recursive=TRUE, include.dirs=TRUE)) path could be the OneDrive directory or Scotland (and is not needed if you're already in the directory you want). Then rownames(subset(fi, isdir)) will contain all the directories. Maybe you want to use grep or other m

Re: [R] grep

2024-07-12 Thread Jorgen Harmse via R-help
which(grepl()) looks odd. Doesn't grep by itself return the correct vector of indices? Regards, Jorgen Harmse. Message: 5 Date: Fri, 12 Jul 2024 17:42:05 +0800 From: Steven Yen mailto:st...@ntu.edu.tw>> To: Uwe Ligges mailto:lig...@statistik.tu-dortmund.de>>, R-help Mailing List mailto:r-h

Re: [R] round and trailing zero

2024-07-30 Thread Jorgen Harmse via R-help
Duncan Murdoch answered your question, but I have another. Are you going to do some computation with the rounded numbers, or are they just for display? (One thing I like about Excel is that I can change the display format of a cell without changing answers that depend on that cell.) In the latte

Re: [R] An error message with the command fm<-1m

2024-08-06 Thread Jorgen Harmse via R-help
> The function is lm(), not 1m(). Eric Berger is correct (except for the extra parentheses), but it is worth pointing out that variable names do not begin with digits. (You can use backticks, assign, & other features to create such names (e.g. to write the Orwellian assignment `2 + 2` <- 5L), b

Re: [R] BUG: atan(1i) / 5 = NaN+Infi ?

2024-09-06 Thread Jorgen Harmse via R-help
It seems to me that the documentation of R's complex class & R's atan function do not tell us what to expect, so (as others have suggested), some additional notes are needed. I think that mathematically atan(1i) should be NA_complex_, but R seems not to use any mathematically standard compactifi

Re: [R] [EXTERNAL] R-help Digest, Vol 260, Issue 19

2024-10-24 Thread Jorgen Harmse via R-help
I think that Stevie Pederson has the right idea, but it is not obvious what the threshold should be. Example: > n <- 2428716; sum(rep(1/n,n)) - 1 [1] -3.297362e-14 I assume that equally large errors in the other direction are also possible. Regards, Jorgen Harmse. -

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

2025-01-06 Thread Jorgen Harmse via R-help
I think Bert Gunter is right, but do you want partial matches (not found by match), and how robust do you want the code to be? f <- function(…) { pos <- match('a', ...names()) if (is.na(pos)) stop("a is required.") …elt(pos) } Incidentally, what is the best way to extract the expression

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

2025-01-07 Thread Jorgen Harmse via R-help
Interesting discussion. A few things occurred to me. Apologies to Iris Simmons: I mixed up his answer with Bert's question. Bert raises questions about promises, and I think they are related to John Sorkin's question. A big difference between R and most other languages is that function argument

Re: [R] R CMD check says no visible binding for global variable

2025-01-29 Thread Jorgen Harmse via R-help
Hi Naresh Gurbuxani, There are already several answers dealing with the specific code that you wrote, but my reaction is to step back a little. R CMD � starts an R session but takes standard input from a file. (In Unix-like systems you might even be able to make an R script into an executable