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)
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,
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
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
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
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.
#
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
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
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
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
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
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
: 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
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
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
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
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
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
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
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
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
.
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
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
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
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
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)
>
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
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:
> 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
(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
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.
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
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
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
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
> 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
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
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.
-
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
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
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
41 matches
Mail list logo