Re: [R] Current version of R, 4.4.0 and patch to correct the bug fix related to the RStudio viewer pane on Windows systems
The developer.r-project.org site lists plans for releases, and no plan is in place yet for a 4.4.1 release. You can look at the history of previous versions if you want to make a guess: 4.3.1: June, 2023 4.2.1: June, 2022 4.1.1: August, 2021 4.0.1: June, 2020 3.6.1: July, 2019 3.5.1: July, 2018 3.4.1: June, 2017 3.3.1: June, 2016 So it's a good guess that it will happen before September, and better than even odds it will be before July. Duncan Murdoch On 2024-05-16 7:39 a.m., Vega, Ann (she/her/hers) via R-help wrote: I help to coordinate the USEPA's R user group. We have over 500 members and our security officer has required us to update to R version 4.4.0 because of the security vulnerability to versions prior. However, we cannot download the patched version because it does not have a signed certificate and Microsoft Defender won't allow us to install it. Most of our users rely on the RStudio viewer pane so we are in a bit of a quandary. We suspect other government agencies are impacted by this as well. Can you give me an estimated time for when another official version will be released with the patch included? I may be able to ask our security officer to allow us to delay our install until that official version is released. Alternatively, if the patched version could have a signed certificate, that would allow us to install it. Thank you. Ann Vega, PSPO She/Her/Hers (Learn More<https://intranet.ord.epa.gov/dei/gender-pronouns>) Office of Science Information Management, Data Architect EPA Office of Research and Development Cincinnati, OH Mobile: 513-418-1922 - or reach out to me on Teams! Hours: Monday-Thursday, 7:30am - 6:00 pm, CDO: Fridays Email: vega@epa.gov<mailto:vega@epa.gov> [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] test2r.mengz1(X)
Google says that function is in the bcdstats package, which isn't on CRAN. It appears to be a private package for a course, kept on Github. Duncan Murdoch On 2024-05-13 12:24 p.m., Alligand, Justine wrote: Dear participants and subscribers of the R-help mailing list, I would like to compare two dependent correlations with one overlapping variable. The Meng Z1 method seemed suitable for this purpose. I found out that the "cocor" package is required for this instrument. I checked several times whether the package was installed and activated and both were the case. I have also tried the "psych" package, but I get the same error in both cases: library(cocor) library(psych) test2r.mengz1(corAVOBMI, corAVVBMI, corAVOAVV, 39) Error in test2r.mengz1(corAVOBMI, corAVVBMI, corAVOAVV, 39) : could not find function "test2r.mengz1" (Translated from German) Do I not have the right package? Or can you recognize another error? Many thanks in advance. Yours faithfully Justine Alligand [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there some way to customize colours for the View output?
I just tried it on an old Windows computer. I don't see dataeditfg in the preferences menu; I think it is the internal variable name used for "dataedittext". The row and column names don't appear to be controllable from that menu, they seem (on my machine) to be displayed in the same colour as the background of a dialog box, i.e. some kind of gray. I don't think R tries to control that colour, but perhaps some Windows setting would change it. Duncan Murdoch On 2024-05-13 4:50 a.m., Iago Giné Vázquez wrote: Hi all, I've just could test your suggestions on using dataedit... entries now, and indeed they work... partially. See, please, the next screenshot: https://ibb.co/Dkn2pVs <https://ibb.co/Dkn2pVs> dataedituser modifies the red borders dataedittext the yellow text dataeditfg... I do not know, specified to green the output of View(mtcars) does not change from that of the screenshot dataeditbg is the (almost) black background, but in the column and row names. I tried the modifying the different colours through the GUI preferences, and the background colour for column and row names did not change. May this be a bug? Thank you for your help. Best regards, Iago *De:* Rolf Turner *Enviat el:* dimarts, 7 de maig de 2024 23:58 *Per a:* Duncan Murdoch *A/c:* Iago Giné Vázquez ; r-help@r-project.org ; Achim Zeileis *Tema:* Re: [R] Is there some way to customize colours for the View output? On Tue, 7 May 2024 06:34:50 -0400 Duncan Murdoch wrote: On 07/05/2024 6:31 a.m., Iago Giné Vázquez wrote: > Thanks Duncan. > > I am currently on Windows. Is there any solution for it? Switch to Linux or MacOS? Fortune nomination! cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Stats. Dep't. (secretaries) phone: +64-9-373-7599 ext. 89622 Home phone: +64-9-480-4619 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Strange variable names in factor regression
On 09/05/2024 8:09 a.m., Naresh Gurbuxani wrote: On converting character variables to ordered factors, regression result has strange names. Is it possible to obtain same variable names with and without intercept? You are getting polynomial contrasts with the ordered factor, because you have the default setting for options("contrasts"), i.e. unordered ordered "contr.treatment" "contr.poly" If you run options(contrasts = c("contr.treatment", "contr.treatment")) you will get the same coefficient names in both cases. By the way, the coefficients have different meanings, so it makes sense they will have different names. It's perhaps a little bit more of a problem that you *don't* get different variable names when an intercept is included or not, because those coefficients also have different meanings. It may also be a little bit of a surprise that you go back to treatment contrasts when you leave out the intercept with the ordered factor, but then it almost never makes sense to leave out the intercept in a polynomial fit. Duncan Murdoch Thanks, Naresh mydf <- data.frame(date = seq.Date(as.Date("2024-01-01"), as.Date("2024-03-31"), by = 1)) mydf[, "wday"] <- weekdays(mydf$date, abbreviate = TRUE) mydf.work <- subset(mydf, !(wday %in% c("Sat", "Sun"))) mydf.weekend <- subset(mydf, wday %in% c("Sat", "Sun")) mydf.work[, "volume"] <- round(rnorm(nrow(mydf.work), mean = 20, sd = 5)) mydf.weekend[, "volume"] <- round(rnorm(nrow(mydf.weekend), mean = 10, sd = 5)) mydf <- rbind(mydf.work, mydf.weekend) reg <- lm(volume ~ wday, data = mydf) ## Variable names as expected coef(reg) (Intercept) wdayMon wdaySat wdaySun wdayThu wdayTue 21.3846154 1.3076923 -12.000 -12.9230769 -1.9230769 -0.6923077 wdayWed -1.6153846 reg <- lm(volume ~ wday - 1, data = mydf) # Variable names as expected coef(reg) wdayFri wdayMon wdaySat wdaySun wdayThu wdayTue wdayWed 21.384615 22.692308 9.384615 8.461538 19.461538 20.692308 19.769231 # Ordered factors for weekday sequence mydf$wday <- factor(mydf$wday, levels = c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"), ordered = TRUE) reg <- lm(volume ~ wday - 1, data = mydf) # Variable names as expected coef(reg) wdayMon wdayTue wdayWed wdayThu wdayFri wdaySat wdaySun 22.692308 20.692308 19.769231 19.461538 21.384615 9.384615 8.461538 reg <- lm(volume ~ wday, data = mydf) # Strange variable names coef(reg) (Intercept) wday.L wday.Q wday.C wday^4 wday^5 17.406593 -12.036715 -4.968654 -1.852819 3.291477 4.263642 wday^6 2.591317 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] losing variable attributes when subsetting model.frame
On 08/05/2024 7:47 a.m., Vito Muggeo via R-help wrote: dear all, I have a simple function f() which, when included in model.frame() via the formula, returns the variable itself with some attributes. However when I specify the subset argument, the attributes get lost, apparently. I would like to extract the attributes also when specifying the subset argument. Of course, I can build the whole dataframe without subsetting, taking the attributes and then build again the dataframe with 'subset', but I am wondering if a more direct (and elegant) solution exists. Any suggestion? Thank you very much, best, Vito #= Here a simple example.. f<- function(x){ attr(x,"vi")<-length(x) x } x<- 1:5 z<-runif(5) y<-rnorm(5) mf<- model.frame(y~f(z)) attr(mf[,2],"vi") #it works mf <- model.frame(y~f(z), subset=x>=3) attr(mf[,2],"vi") #it does not work I would guess that subsetting uses [] indexing on each column, with a logical argument. If that is true, then one solution (which is less direct, but maybe someone would call it elegant) is to put a class on the result of `f()`, and define a `[` method for that class that preserves the attributes you want to preserve. In your example: f <- function(x) { attr(x, "vi") <- length(x) class(x) <- c("withAttributes", class(x)) x } `[.withAttributes` <- function(x, i) { subset <- NextMethod() attr(subset, "vi") <- attr(x, "vi") subset } x<- 1:5 z<-runif(5) y<-rnorm(5) mf <- model.frame(y~f(z), subset=x>=3) attr(mf[,2],"vi") #it works #> [1] 5 Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there some way to customize colours for the View output?
On 07/05/2024 6:31 a.m., Iago Giné Vázquez wrote: Thanks Duncan. I am currently on Windows. Is there any solution for it? Switch to Linux or MacOS? Duncan Murdoch Best regards, Iago *De:* Duncan Murdoch *Enviat el:* dimarts, 7 de maig de 2024 12:24 *Per a:* Iago Giné Vázquez ; r-help@r-project.org *Tema:* Re: [R] Is there some way to customize colours for the View output? If you are using X11, then the paragraph on X resources is relevant. Create a file named .Xresources in your home directory, and put a line like R_dataentry.background: green in it. On my Mac, this has to be in place before Xquartz is started. There is probably a similar restriction on other platforms. Colour names (used for foreground and background) can be words or hex colors like #ff . I don't know the format for "geometry", but I'd guess it's like the -geometry argument to X11 apps, e.g. 1000x1000+0+0. If you are on Windows, none of this is relevant. Duncan Murdoch On 07/05/2024 5:51 a.m., Iago Giné Vázquez wrote: Hi all, As the email subject tells, I write to ask if there is the chance to customize the colours (and in particular the background) of the `View` output window. In the View help, it is told that: On Windows, the initial size of the data viewer window is taken from the default dimensions of a pager (see Rconsole), but adjusted downwards to show a whole number of rows and columns. So if it works for the sizes, it could work for the colours. But after modifying ## Colours for console and pager(s) # (see rw/etc/rgb.txt for the known colours). background = gray9 normaltext = yellow usertext = YellowGreen highlight = golderod I did not have success. On the other hand, in the data.entry it is told that The data entry window responds to X resources of class R_dataentry. Resources foreground, background and geometry are utilized. But I do not know if this is related and how to modify those resources. Can someone help me? If this is not possible, is there any chance of making a feature request of this to R-devel? (I mean, I could write to R-devel list, but do you think there would be any interest in developing this?) Thanks! Best regards, Iago [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there some way to customize colours for the View output?
If you are using X11, then the paragraph on X resources is relevant. Create a file named .Xresources in your home directory, and put a line like R_dataentry.background: green in it. On my Mac, this has to be in place before Xquartz is started. There is probably a similar restriction on other platforms. Colour names (used for foreground and background) can be words or hex colors like #ff . I don't know the format for "geometry", but I'd guess it's like the -geometry argument to X11 apps, e.g. 1000x1000+0+0. If you are on Windows, none of this is relevant. Duncan Murdoch On 07/05/2024 5:51 a.m., Iago Giné Vázquez wrote: Hi all, As the email subject tells, I write to ask if there is the chance to customize the colours (and in particular the background) of the `View` output window. In the View help, it is told that: On Windows, the initial size of the data viewer window is taken from the default dimensions of a pager (see Rconsole), but adjusted downwards to show a whole number of rows and columns. So if it works for the sizes, it could work for the colours. But after modifying ## Colours for console and pager(s) # (see rw/etc/rgb.txt for the known colours). background = gray9 normaltext = yellow usertext = YellowGreen highlight = golderod I did not have success. On the other hand, in the data.entry it is told that The data entry window responds to X resources of class R_dataentry. Resources foreground, background and geometry are utilized. But I do not know if this is related and how to modify those resources. Can someone help me? If this is not possible, is there any chance of making a feature request of this to R-devel? (I mean, I could write to R-devel list, but do you think there would be any interest in developing this?) Thanks! Best regards, Iago [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange behavior in base::as.double
On 01/05/2024 11:32 a.m., Carl Witthoft wrote: Hello. I'm running R 4.4.0 on an iMac Venture 13.5.2 . There appears to be a bug in as.double(). Create a string with a numeric digits followed by a single letter a thru f (as tho' it's base 16). for K in (a,b,c,d, and f ) , as.double( '123K') returns NA but as.double('123e') returns 123 -- or whatever the first digit is. Please let me know if there are additional tests I can try . This has been mentioned in the news recently. 123e was taken as scientific format, with an implied 0 at the end, i.e. 123e0. That is no longer true after the recent fix; I'm not sure if it is in R 4.4.0-patched yet. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] any and all
On 12/04/2024 3:52 p.m., avi.e.gr...@gmail.com wrote: Base R has generic functions called any() and all() that I am having trouble using. It works fine when I play with it in a base R context as in: all(any(TRUE, TRUE), any(TRUE, FALSE)) [1] TRUE all(any(TRUE, TRUE), any(FALSE, FALSE)) [1] FALSE But in a tidyverse/dplyr environment, it returns wrong answers. Consider this example. I have data I have joined together with pairs of columns representing a first generation and several other pairs representing additional generations. I want to consider any pair where at least one of the pair is not NA as a success. But in order to keep the entire row, I want all three pairs to have some valid data. This seems like a fairly common reasonable thing often needed when evaluating data. So to make it very general, I chose to do something a bit like this: We can't really help you without a reproducible example. It's not enough to show us something that doesn't run but is a bit like the real code. Duncan Murdoch result <- filter(mydata, all( any(!is.na(first.a), !is.na(first.b)), any(!is.na(second.a), !is.na(second.b)), any(!is.na(third.a), !is.na(third.b I apologize if the formatting is not seen properly. The above logically should work. And it should be extendable to scenarios where you want at least one of M columns to contain data as a group with N such groups of any size. But since it did not work, I tried a plan that did work and feels silly. I used mutate() to make new columns such as: result <- mydata |> mutate( usable.1 = (!is.na(first.a) | !is.na(first.b)), usable.2 = (!is.na(second.a) | !is.na(second.b)), usable.3 = (!is.na(third.a) | !is.na(third.b)), usable = (usable.1 & usable.2 & usable.3) ) |> filter(usable == TRUE) The above wastes time and effort making new columns so I can check the calculations then uses the combined columns to make a Boolean that can be used to filter the result. I know this is not the place to discuss dplyr. I want to check first if I am doing anything wrong in how I use any/all. One guess is that the generic is messed with by dplyr or other packages I libraried. And, of course, some aspects of delayed evaluation can interfere in subtle ways. I note I have had other problems with these base R functions before and generally solved them by not using them, as shown above. I would much rather use them, or something similar. Avi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Debugging functions defined (locally) inside another functions
On 12/04/2024 8:15 a.m., Iago Giné Vázquez wrote: Hi all, I am trying to debug an error of a function g defined and used inside another function f of a package. So I have f <- function(whatever){ ... g <- function(whatever2){ ... } ... } If I wanted to debug some thing directly inside f I would do debug(f). But this does not go inside g code. On the other hand, debug(g) does not work as g is not a defined function in the namespace of the package. Is there some way to debug errors inside g? The easiest case is if you have access to the source code. Just put a browser() statement at the start of g, i.e. change it to g <- function(whatever2){ browser() ... } and it will break very similarly to what happens if you have set debug(g). Another possibility if you have the source but don't want to edit it is to use trace. Suppose that the definition of g is in source.R at lines 100 to 120. Then you can run setBreakpoint("source.R#101") to set a breakpoint via trace() just before line 101 runs. trace() has lots of options; it can just print things, or call browser(), etc. They are available in setBreakpoint(). If you are executing code from a package and you don't have the source handy it's a bit tedious, but you can still do the search that setBreakpoint() does to find the source. For example, let's set a breakpoint just before the print statement in g in this example: f <- function() { g <- function() { print("this is g") } print("this is f") g() } You need to find the location of that line in f. Look at as.list(body(f)): > as.list(body(f)) [[1]] `{` [[2]] g <- function() { print("this is g") } [[3]] print("this is f") [[4]] g() So we need to look within entry 2: > as.list(body(f)[[2]]) [[1]] `<-` [[2]] g [[3]] function() { print("this is g") } Continue drilling down: > as.list(body(f)[[c(2,3)]]) [[1]] `function` [[2]] NULL [[3]] { print("this is g") } [[4]] function() { print("this is g") } > as.list(body(f)[[c(2,3, 3)]]) [[1]] `{` [[2]] print("this is g") So now we know the print statement is at location c(2,3,3,2). Set a browser call there: > trace(f, at=list(c(2,3,3,2)), tracer = quote(browser())) [1] "f" > body(f) { g <- function() { { .doTrace(browser(), "step 2,3,3,2") print("this is g") } } print("this is f") g() } Note that the "at" argument needs to be a list to drill down; if you just said at=c(2,3,3,2) it would set breakpoints at step 2 and 3. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Regexp pattern but fixed replacement?
On 11/04/2024 12:58 p.m., Iris Simmons wrote: 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/04650eddd6d844963b6d7aac02bd8d13cbf440d4/src/main/grep.c <https://github.com/wch/r-source/blob/04650eddd6d844963b6d7aac02bd8d13cbf440d4/src/main/grep.c> particularly functions R_pcre_string_adj and wstring_adj. So just double the backslashes in replacement and you'll be good to go. Thanks, that's what I've done. Duncan Murdoch On Thu, Apr 11, 2024, 12:36 Duncan Murdoch <mailto:murdoch.dun...@gmail.com>> wrote: I noticed this issue in stringr::str_replace, but it also affects sub() in base R. If the pattern in a call to one of these needs to be a regular expression, then backslashes in the replacement text are treated specially. For example, gsub("a|b", "\\", "abcdef") gives "def", not "def" as I wanted. To get the latter, I need to escape the replacement backslashes, e.g. gsub("a|b", "", "abcdef") which gives "cdef". I have two questions: 1. Is there a variant on sub or str_replace which allows the pattern to be declared as a regular expression, but the replacement to be declared as fixed? 2. To get what I want, I can double the backslashes in the replacement text. This would do that: replacement <- gsub("", "", replacement) Are there any other special characters to worry about besides backslashes? Duncan Murdoch __ R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Regexp pattern but fixed replacement?
On 11/04/2024 12:57 p.m., Dave Dixon wrote: Backslashes in regex expressions in R are maddening, but they make sense. R string handling interprets your replacement string "\\" as just one backslash. Your string is received by gsub as "\" - that is, just the control backslash, NOT the character backslash. gsub is expecting to see \0, \1, \2, or some other control starting with backslash. If you want gsub to replace with a backslash character, you have to send it as "\\". In order to get two backslash characters in an R string, you have to double them ALL: "". You can use "\\" if the pattern is declared as "fixed", via sub("a", "\\", "abcdef", fixed = TRUE) or stringr::str_replace("abcdef", fixed("a"), "\\") My first question was whether there is a sub-like function with a way to declare the pattern as a regexp, but the replacement as fixed. Thanks for your answer to my second question. Duncan Murdoch The string that is output is an R string: the backslashes are escaped with a backslash, so "" really means two backslashes. There are lots of special characters in the search string, but only one in the replacement string: backslash. Here's my favorite resource on this topic is https://www.regular-expressions.info/replacecharacters.html On 4/11/24 10:35, Duncan Murdoch wrote: I noticed this issue in stringr::str_replace, but it also affects sub() in base R. If the pattern in a call to one of these needs to be a regular expression, then backslashes in the replacement text are treated specially. For example, gsub("a|b", "\\", "abcdef") gives "def", not "def" as I wanted. To get the latter, I need to escape the replacement backslashes, e.g. gsub("a|b", "", "abcdef") which gives "cdef". I have two questions: 1. Is there a variant on sub or str_replace which allows the pattern to be declared as a regular expression, but the replacement to be declared as fixed? 2. To get what I want, I can double the backslashes in the replacement text. This would do that: replacement <- gsub("", "", replacement) Are there any other special characters to worry about besides backslashes? Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Regexp pattern but fixed replacement?
I noticed this issue in stringr::str_replace, but it also affects sub() in base R. If the pattern in a call to one of these needs to be a regular expression, then backslashes in the replacement text are treated specially. For example, gsub("a|b", "\\", "abcdef") gives "def", not "def" as I wanted. To get the latter, I need to escape the replacement backslashes, e.g. gsub("a|b", "", "abcdef") which gives "cdef". I have two questions: 1. Is there a variant on sub or str_replace which allows the pattern to be declared as a regular expression, but the replacement to be declared as fixed? 2. To get what I want, I can double the backslashes in the replacement text. This would do that: replacement <- gsub("", "\\\\", replacement) Are there any other special characters to worry about besides backslashes? Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] split a factor into single elements
On 28/03/2024 7:48 a.m., Stefano Sofia wrote: as.factor(2024, 12, 1, 0, 0) That doesn't work. You need to put the numbers in a single vector as Fabio did, or you'll see this: Error in as.factor(2024, 12, 1, 0, 0) : unused arguments (12, 1, 0, 0) Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building Packages.
I posted a description of their changes this morning. Duncan Murdoch On 21/03/2024 11:37 a.m., avi.e.gr...@gmail.com wrote: With all this discussion, I shudder to ask this. I may have missed the answers but the discussion seems to have been about identifying and solving the problem rapidly rather than what maybe is best going forward if all parties agree. What was the motivation for what RSTUDIO did for their version and the decision to replace what came with utils unless someone very explicitly over-rode them by asking for the original? Is their version better in other ways? Is there a possibility the two implementations may someday merge into something that meets several sets of needs or are they incompatible? Is there agreement that what broke with the substitution is a valid use or is it something that just happens to work on the utils version if not patched? -Original Message- From: R-help On Behalf Of Duncan Murdoch Sent: Thursday, March 21, 2024 5:53 AM To: peter dalgaard Cc: Jorgen Harmse ; r-help@r-project.org; Martin Maechler Subject: Re: [R] Building Packages. Yes, you're right. The version found in the search list entry for "package:utils" is the RStudio one; the ones found with two or three colons are the original. Duncan Murdoch On 21/03/2024 5:48 a.m., peter dalgaard wrote: Um, what's with the triple colon? At least on my install, double seems to suffice: identical(utils:::install.packages, utils::install.packages) [1] TRUE install.packages function (...) .rs.callAs(name, hook, original, ...) -pd On 21 Mar 2024, at 09:58 , Duncan Murdoch wrote: The good news for Jorgen (who may not be reading this thread any more) is that one can still be sure of getting the original install.packages() by using utils:::install.packages( ... ) with *three* colons, to get the internal (namespace) version of the function. Duncan Murdoch On 21/03/2024 4:31 a.m., Martin Maechler wrote: "Duncan Murdoch on Wed, 20 Mar 2024 13:20:12 -0400 writes: > On 20/03/2024 1:07 p.m., Duncan Murdoch wrote: >> On 20/03/2024 12:37 p.m., Ben Bolker wrote: >>> Ivan, can you give more detail on this? I've heard this >>> issue mentioned, but when I open RStudio and run >>> find("install.packages") it returns >>> "utils::install.packages", and running dump() from >>> within RStudio console and from an external "R >>> --vanilla" gives identical results. >>> >>> I thought at one point this might only refer to the GUI >>> package-installation interface, but you seem to be >>> saying it's the install.packages() function as well. >>> >>> Running an up-to-date RStudio on Linux, FWIW -- maybe >>> weirdness only happens on other OSs? >> >> On MacOS, I see this: >> >> > install.packages function (...) .rs.callAs(name, hook, >> original, ...) >> >> I get the same results as you from find(). I'm not sure >> what RStudio is doing to give a different value for the >> function than what find() sees. > Turns out that RStudio replaces the install.packages > object in the utils package. > Duncan Murdoch Yes, and this has been the case for several years now, and I have mentioned this several times, too (though some of it possibly not in a public R-* mailing list). And yes, that they modify the package environment as.environment("package:utils") but leave the namespace asNamespace("utils") unchanged, makes it harder to see what's going on (but also has less severe consequences; if they kept to the otherwise universal *rule* that the namespace and package must have the same objects apart from those only in the namespace, people would not even have access to R's true install.packages() but only see the RStudio fake^Hsubstitute.. We are still not happy with their decision. Also help(install.packages) goes to R's documentation of R's install.packages, so there's even more misleading of useRs. Martin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ___
Re: [R] [External] Re: Building Packages. (fwd)
If you are wondering why RStudio did this, you can see their substitute function using (parent.env(environment(install.packages)))$hook They appear to do these things: - Allow package installation to be disabled. - Check if a package to be installed is already loaded, so that RStudio can restart R for the install. - Add Rtools to the PATH if necessary. - Trigger an event to say that something is about to be changed about the installed packages, presumably so that they can mark a cached list of installed packages as stale. - Call the original function. I think all of these things could be done if install.packages() called a hook at the start, as library() does (via attachNamespace()) when a package is attached. It might be that putting the wrapper code into tools:rstudio would cause confusion for users when there were two objects of the same name on the search list, though I don't see how. Duncan Murdoch On 21/03/2024 7:44 a.m., luke-tierney--- via R-help wrote: [forgot to copy to R-help so re-sending] -- Forwarded message -- Date: Thu, 21 Mar 2024 11:41:52 + From: luke-tier...@uiowa.edu To: Duncan Murdoch Subject: Re: [External] Re: [R] Building Packages. At least on my installed version (which tells me it is out of date) they appear to just be modifying the "package:utils" parent frame of the global search path. There seem to be a few others: checkUtilsFun <- function(n) identical(get(n, "package:utils"), get(n, getNamespace("utils"))) names(which(! sapply(ls("package:utils", all = TRUE), checkUtilsFun))) ## [1] "bug.report" "file.edit""help.request" ## [4] "history" "install.packages" "remove.packages" ## [7] "View" I don't know why they don't put these overrides in the tools:rstudio frame. At least that would make them more visible. You can fix all of these with something like local({ up <- match("package:utils", search()) detach("package:utils") library(utils, pos = up) }) or just install.packages with local({ up <- match("package:utils", search()) unlockBinding("install.packages", pos.to.env(up)) assign("install.packages", utils::install.packages, "package:utils") lockBinding("install.packages", pos.to.env(up)) }) Best, luke On Thu, 21 Mar 2024, Duncan Murdoch wrote: Yes, you're right. The version found in the search list entry for "package:utils" is the RStudio one; the ones found with two or three colons are the original. Duncan Murdoch On 21/03/2024 5:48 a.m., peter dalgaard wrote: Um, what's with the triple colon? At least on my install, double seems to suffice: identical(utils:::install.packages, utils::install.packages) [1] TRUE install.packages function (...) .rs.callAs(name, hook, original, ...) -pd On 21 Mar 2024, at 09:58 , Duncan Murdoch wrote: The good news for Jorgen (who may not be reading this thread any more) is that one can still be sure of getting the original install.packages() by using utils:::install.packages( ... ) with *three* colons, to get the internal (namespace) version of the function. Duncan Murdoch On 21/03/2024 4:31 a.m., Martin Maechler wrote: "Duncan Murdoch on Wed, 20 Mar 2024 13:20:12 -0400 writes: > On 20/03/2024 1:07 p.m., Duncan Murdoch wrote: >> On 20/03/2024 12:37 p.m., Ben Bolker wrote: >>> Ivan, can you give more detail on this? I've heard this >>> issue mentioned, but when I open RStudio and run >>> find("install.packages") it returns >>> "utils::install.packages", and running dump() from >>> within RStudio console and from an external "R >>> --vanilla" gives identical results. >>> >>> I thought at one point this might only refer to the GUI >>> package-installation interface, but you seem to be >>> saying it's the install.packages() function as well. >>> >>> Running an up-to-date RStudio on Linux, FWIW -- maybe >>> weirdness only happens on other OSs? >> >> On MacOS, I see this: >> >> > install.packages function (...) .rs.callAs(name, hook, >> original, ...) >> >> I get the same results as you from find(). I'm not sure >> what RStudio is doing to give a different value for the >> function than what find() sees. > Turns out that RStudio replaces the install.packages > object in the utils package. > Duncan Murdoch Yes, and this has been the case for several years now, and I have mentioned this several times, too (thoug
Re: [R] Building Packages.
Yes, you're right. The version found in the search list entry for "package:utils" is the RStudio one; the ones found with two or three colons are the original. Duncan Murdoch On 21/03/2024 5:48 a.m., peter dalgaard wrote: Um, what's with the triple colon? At least on my install, double seems to suffice: identical(utils:::install.packages, utils::install.packages) [1] TRUE install.packages function (...) .rs.callAs(name, hook, original, ...) -pd On 21 Mar 2024, at 09:58 , Duncan Murdoch wrote: The good news for Jorgen (who may not be reading this thread any more) is that one can still be sure of getting the original install.packages() by using utils:::install.packages( ... ) with *three* colons, to get the internal (namespace) version of the function. Duncan Murdoch On 21/03/2024 4:31 a.m., Martin Maechler wrote: "Duncan Murdoch on Wed, 20 Mar 2024 13:20:12 -0400 writes: > On 20/03/2024 1:07 p.m., Duncan Murdoch wrote: >> On 20/03/2024 12:37 p.m., Ben Bolker wrote: >>> Ivan, can you give more detail on this? I've heard this >>> issue mentioned, but when I open RStudio and run >>> find("install.packages") it returns >>> "utils::install.packages", and running dump() from >>> within RStudio console and from an external "R >>> --vanilla" gives identical results. >>> >>> I thought at one point this might only refer to the GUI >>> package-installation interface, but you seem to be >>> saying it's the install.packages() function as well. >>> >>> Running an up-to-date RStudio on Linux, FWIW -- maybe >>> weirdness only happens on other OSs? >> >> On MacOS, I see this: >> >> > install.packages function (...) .rs.callAs(name, hook, >> original, ...) >> >> I get the same results as you from find(). I'm not sure >> what RStudio is doing to give a different value for the >> function than what find() sees. > Turns out that RStudio replaces the install.packages > object in the utils package. > Duncan Murdoch Yes, and this has been the case for several years now, and I have mentioned this several times, too (though some of it possibly not in a public R-* mailing list). And yes, that they modify the package environment as.environment("package:utils") but leave the namespace asNamespace("utils") unchanged, makes it harder to see what's going on (but also has less severe consequences; if they kept to the otherwise universal *rule* that the namespace and package must have the same objects apart from those only in the namespace, people would not even have access to R's true install.packages() but only see the RStudio fake^Hsubstitute.. We are still not happy with their decision. Also help(install.packages) goes to R's documentation of R's install.packages, so there's even more misleading of useRs. Martin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building Packages.
The good news for Jorgen (who may not be reading this thread any more) is that one can still be sure of getting the original install.packages() by using utils:::install.packages( ... ) with *three* colons, to get the internal (namespace) version of the function. Duncan Murdoch On 21/03/2024 4:31 a.m., Martin Maechler wrote: "Duncan Murdoch on Wed, 20 Mar 2024 13:20:12 -0400 writes: > On 20/03/2024 1:07 p.m., Duncan Murdoch wrote: >> On 20/03/2024 12:37 p.m., Ben Bolker wrote: >>> Ivan, can you give more detail on this? I've heard this >>> issue mentioned, but when I open RStudio and run >>> find("install.packages") it returns >>> "utils::install.packages", and running dump() from >>> within RStudio console and from an external "R >>> --vanilla" gives identical results. >>> >>> I thought at one point this might only refer to the GUI >>> package-installation interface, but you seem to be >>> saying it's the install.packages() function as well. >>> >>> Running an up-to-date RStudio on Linux, FWIW -- maybe >>> weirdness only happens on other OSs? >> >> On MacOS, I see this: >> >> > install.packages function (...) .rs.callAs(name, hook, >> original, ...) >> >> I get the same results as you from find(). I'm not sure >> what RStudio is doing to give a different value for the >> function than what find() sees. > Turns out that RStudio replaces the install.packages > object in the utils package. > Duncan Murdoch Yes, and this has been the case for several years now, and I have mentioned this several times, too (though some of it possibly not in a public R-* mailing list). And yes, that they modify the package environment as.environment("package:utils") but leave the namespace asNamespace("utils") unchanged, makes it harder to see what's going on (but also has less severe consequences; if they kept to the otherwise universal *rule* that the namespace and package must have the same objects apart from those only in the namespace, people would not even have access to R's true install.packages() but only see the RStudio fake^Hsubstitute.. We are still not happy with their decision. Also help(install.packages) goes to R's documentation of R's install.packages, so there's even more misleading of useRs. Martin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building Packages.
On 20/03/2024 1:07 p.m., Duncan Murdoch wrote: On 20/03/2024 12:37 p.m., Ben Bolker wrote: Ivan, can you give more detail on this? I've heard this issue mentioned, but when I open RStudio and run find("install.packages") it returns "utils::install.packages", and running dump() from within RStudio console and from an external "R --vanilla" gives identical results. I thought at one point this might only refer to the GUI package-installation interface, but you seem to be saying it's the install.packages() function as well. Running an up-to-date RStudio on Linux, FWIW -- maybe weirdness only happens on other OSs? On MacOS, I see this: > install.packages function (...) .rs.callAs(name, hook, original, ...) I get the same results as you from find(). I'm not sure what RStudio is doing to give a different value for the function than what find() sees. Turns out that RStudio replaces the install.packages object in the utils package. Duncan Murdoch Duncan Murdoch Ben Bolker On 2024-03-20 12:13 p.m., Ivan Krylov via R-help wrote: В Wed, 20 Mar 2024 16:02:27 + Jorgen Harmse via R-help пишет: install.packages(tar,type='source',repos=NULL) Error in library(jhBase) : there is no package called ‘jhBase’ Execution halted Warning in install.packages(tar, type = "source", repos = NULL) : installation of package ‘/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz’ had non-zero exit status Using RStudio? It happens to override install.packages with a function that doesn't quite handle file paths. Try utils::install.packages(tar, type = "source", repos = NULL). __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building Packages.
Is the source for your package online somewhere? Duncan Murdoch On 20/03/2024 1:00 p.m., Jorgen Harmse via R-help wrote: Thank you, but I think I was already using utils. Regards, Jorgen. environment(install.packages) utils::install.packages('/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz',type='source',repos=NULL) Error in library(jhBase) : there is no package called �jhBase� Execution halted Warning in utils::install.packages("/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz", : installation of package �/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz� had non-zero exit status 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) Error in library(jhBase) : there is no package called �jhBase� Execution halted Warning in install.packages(tar, type = "source", repos = NULL) : installation of package �/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz� had non-zero exit status Using RStudio? It happens to override install.packages with a function that doesn't quite handle file paths. Try utils::install.packages(tar, type = "source", repos = NULL). -- Best regards, Ivan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building Packages.
On 20/03/2024 12:37 p.m., Ben Bolker wrote: Ivan, can you give more detail on this? I've heard this issue mentioned, but when I open RStudio and run find("install.packages") it returns "utils::install.packages", and running dump() from within RStudio console and from an external "R --vanilla" gives identical results. I thought at one point this might only refer to the GUI package-installation interface, but you seem to be saying it's the install.packages() function as well. Running an up-to-date RStudio on Linux, FWIW -- maybe weirdness only happens on other OSs? On MacOS, I see this: > install.packages function (...) .rs.callAs(name, hook, original, ...) I get the same results as you from find(). I'm not sure what RStudio is doing to give a different value for the function than what find() sees. Duncan Murdoch Ben Bolker On 2024-03-20 12:13 p.m., Ivan Krylov via R-help wrote: В Wed, 20 Mar 2024 16:02:27 + Jorgen Harmse via R-help пишет: install.packages(tar,type='source',repos=NULL) Error in library(jhBase) : there is no package called ‘jhBase’ Execution halted Warning in install.packages(tar, type = "source", repos = NULL) : installation of package ‘/Users/jharmse/Library/CloudStorage/OneDrive-RokuInc/jhBase_1.0.1.tar.gz’ had non-zero exit status Using RStudio? It happens to override install.packages with a function that doesn't quite handle file paths. Try utils::install.packages(tar, type = "source", repos = NULL). __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to invert axis within defined range with ggplot2 scale_y_reverse?
On 05/03/2024 7:16 a.m., Luigi Marongiu wrote: A <- rep(c(0, 3, 6, 12, 24), 3) B <- c(rep(0,5), rep(1,5), rep(2,5)) V <- c(27.5,27.01,27.75,27.98,27.4,25.69, 26.17,27.78,26.08, 24.97,23.18,21.78,22.49,21.85,22.2) df <- data.frame(Conc = A, Time = B, Value = V) df$Conc = as.factor(df$Conc) df$Time = as.factor(df$Time) library(ggplot2) ggplot(df, aes(x=Time, y=Value, colour=Conc, group=Conc)) + geom_line() + scale_y_reverse(limits = c(20,30)) + geom_point(size=6) + scale_colour_manual(values = COLS) The limits should be `c(30,20)`. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Packages sometimes don't update, but no error or warning is thrown
The normal way to update packages is to use update.packages() rather than install.packages(). Likely the problem you're having is from using install.packages() (or RStudio using it). I normally use update.packages(ask=FALSE), but if you want to pick and choose, you could use the default which will prompt you for each one. Duncan Murdoch On 16/02/2024 11:33 a.m., Philipp Schneider wrote: Hey everyone, Thanks for all the input. It's happening again. This time for the packages "DBI", "parallelly", "segmented", "survival", "V8". So, RStudio shows updates for those and updating them via RStudio leads to this output: ``` > install.packages(c("DBI", "parallelly", "segmented", "survival", "V8")) trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/DBI_1.2.0.tgz' <https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/DBI_1.2.0.tgz'> Content type 'application/x-gzip' length 822755 bytes (803 KB) == downloaded 803 KB trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/parallelly_1.36.0.tgz' <https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/parallelly_1.36.0.tgz'> Content type 'application/x-gzip' length 349831 bytes (341 KB) == downloaded 341 KB trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/segmented_2.0-2.tgz' <https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/segmented_2.0-2.tgz'> Content type 'application/x-gzip' length 1210146 bytes (1.2 MB) == downloaded 1.2 MB trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/survival_3.5-7.tgz' <https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/survival_3.5-7.tgz'> Content type 'application/x-gzip' length 7101721 bytes (6.8 MB) == downloaded 6.8 MB trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/V8_4.4.1.tgz' <https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.3/V8_4.4.1.tgz'> Content type 'application/x-gzip' length 10093069 bytes (9.6 MB) == downloaded 9.6 MB The downloaded binary packages are in /var/folders/ws/XXX/T//YYY/downloaded_packages ``` After that, all the packages are still updatable. No warning, no error, but also no updated packages. utils::install.packages(c("DBI", "parallelly", "segmented", "survival", "V8")) leads to the exact same output. The only difference, if I run it directly from command-line is, that I have to select a mirror. After that it's again the same output. The DBI package for example is installed with version 1.2.0, which is the latest available macOS arm64 binary. However, there is an update available for other binaries or source. So, I guess in the end, it's not the install.packages() that is failing, but the check for updates from RStudio. On the other hand, shouldn't there be at least a warning that there are new updates available, just no new binaries. Best, Philipp Gesendet: Mittwoch, 14. Februar 2024 um 18:44 Uhr Von: "Duncan Murdoch" An: "Martin Maechler" , "Berwin A Turlach" Cc: "gernophil--- via R-help" Betreff: Re: [R] Packages sometimes don't update, but no error or warning is thrown On 14/02/2024 5:50 a.m., Martin Maechler wrote: >>>>>> Berwin A Turlach >>>>>> on Wed, 14 Feb 2024 11:47:41 +0800 writes: >>>>>> Berwin A Turlach >>>>>> on Wed, 14 Feb 2024 11:47:41 +0800 writes: > > > G'day Philipp, > > > On Tue, 13 Feb 2024 09:59:17 +0100 gernophil--- via R-help > > wrote: > > >> this question is related to this > >> (https://community.rstudio.com/t/packages-are-not-updating/166214/3 <https://community.rstudio.com/t/packages-are-not-updating/166214/3>), > >> [...] > > >> To sum it up: If I am updating packages (be it via > >> Bioconductor or CRAN) some packages simply don’t update, > >> [...] > > >> I would expect any kind of message that the package will > >> not be updated, since no newer binary is available or a > >> prompt, if I want to compile from source. > > > RStudio is doing its own thing for some task, including > > 'install.packages()' (and for some reasons, at least on > > the platforms on which I use RStudio, RStudio calls > > 'install.packages()' and not 'update.packages()' when an > > update is requested via the GUI). See: > > RStudio> install.packages > > fu
Re: [R] Packages sometimes don't update, but no error or warning is thrown
On 14/02/2024 5:50 a.m., Martin Maechler wrote: Berwin A Turlach on Wed, 14 Feb 2024 11:47:41 +0800 writes: Berwin A Turlach on Wed, 14 Feb 2024 11:47:41 +0800 writes: > G'day Philipp, > On Tue, 13 Feb 2024 09:59:17 +0100 gernophil--- via R-help > wrote: >> this question is related to this >> (https://community.rstudio.com/t/packages-are-not-updating/166214/3), >> [...] >> To sum it up: If I am updating packages (be it via >> Bioconductor or CRAN) some packages simply don’t update, >> [...] >> I would expect any kind of message that the package will >> not be updated, since no newer binary is available or a >> prompt, if I want to compile from source. > RStudio is doing its own thing for some task, including > 'install.packages()' (and for some reasons, at least on > the platforms on which I use RStudio, RStudio calls > 'install.packages()' and not 'update.packages()' when an > update is requested via the GUI). See: RStudio> install.packages > function (...) .rs.callAs(name, hook, original, ...) > > compared to: R> install.packages > function (pkgs, lib, repos = getOption("repos"), > contriburl = contrib.url(repos, type), method, available = > NULL, destdir = NULL, dependencies = NA, type = > getOption("pkgType"), configure.args = > getOption("configure.args"), configure.vars = > getOption("configure.vars"), clean = FALSE, Ncpus = > getOption("Ncpus", 1L), verbose = getOption("verbose"), > libs_only = FALSE, INSTALL_opts, quiet = FALSE, > keep_outputs = FALSE, ...) { [...] > So if you use Install/Update in the Packages tab of > RStudio and do not experience the behaviour you are > expecting, it is something that you need to discuss with > Posit, not with R. :) >> However, the only message I get is: ``` trying URL >> '' > The package name has the version number encoded in it, so > theoretical you should be able to tell at this point > whether the package that is downloaded is the version that > is already installed, hence no update will happen. > Best wishes, > Berwin Yes, thank's a lot, Berwin. Indeed I've raised the fact that RStudio hides R's own install.packages() from the user and uses its own, undocumented one ... this has been the case for quite a few years. I found out during teaching --- one of the few times, I use RStudio to use R... in another case where RStudio's install.packages() behaved differently than R's. I'm pretty sure this is reason for quite a bit of confusion... Did they ignore your bug report? Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Skip jumps in curve
It should be pretty easy to generalize my version of the `plot.gamma()` function to a version of `curve()` with an extra `discontinuities` argument. Duncan Murdoch On 13/02/2024 1:44 p.m., Leo Mada wrote: Dear Duncan, Thank you very much for the response. I suspected that such an option has not been implemented yet. The plot was very cluttered due to those vertical lines. Fortunately, the gamma function is easy to handle. But the feature remains on my wishlist as useful more in general. Sincerely, Leonard *From:* Duncan Murdoch *Sent:* Tuesday, February 13, 2024 6:05 PM *To:* Leo Mada ; r-help@r-project.org *Subject:* Re: [R] Skip jumps in curve On 13/02/2024 10:29 a.m., Leo Mada via R-help wrote: Dear R-Users, Is there a way to skip over without plotting the jumps/discontinuities in curve()? I have not seen such an option, but maybe I am missing something. plot.gamma = function(xlim = c(-6, -1), ylim = c(-1,3), hline = NULL, n = 1000) { curve(gamma(x), from = xlim[1], to = xlim[2], ylim=ylim, n=n); if( ! is.null(hline)) abline(h = hline, col = "green"); } Euler = 0.57721566490153286060651209008240243079; plot.gamma(hline = Euler) Adding an option to the function curve may be useful: options = c("warn", "silent", "unconnected") This is part of some experiments in math; but that's another topic. For latest version: https://github.com/discoleo/R/blob/master/Math/Integrals.Gamma.Inv.R <https://github.com/discoleo/R/blob/master/Math/Integrals.Gamma.Inv.R> If you know where the discontinuities are, plot multiple times with the discontinuities as endpoints: plot.gamma = function(xlim = c(-6, -1), ylim = c(-1,3), hline = NULL, n = 1000) { start <- floor(xlim[1]):floor(xlim[2]) end <- start + 1 start[1] <- xlim[1] end[length(end)] <- xlim[2] n <- round(n/length(start)) curve(gamma(x), from = start[1], to = end[1], ylim=ylim, n=n, xlim = xlim) for (i in seq_along(start)[-1]) curve(gamma(x), from = start[i], to = end[i], add = TRUE, n) if( ! is.null(hline)) abline(h = hline, col = "green"); } Euler = 0.57721566490153286060651209008240243079; plot.gamma(hline = Euler) If you don't know where the discontinuities are, it would be much harder, because discontinuities can be hard to detect unless the jumps are really big. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Skip jumps in curve
On 13/02/2024 10:29 a.m., Leo Mada via R-help wrote: Dear R-Users, Is there a way to skip over without plotting the jumps/discontinuities in curve()? I have not seen such an option, but maybe I am missing something. plot.gamma = function(xlim = c(-6, -1), ylim = c(-1,3), hline = NULL, n = 1000) { curve(gamma(x), from = xlim[1], to = xlim[2], ylim=ylim, n=n); if( ! is.null(hline)) abline(h = hline, col = "green"); } Euler = 0.57721566490153286060651209008240243079; plot.gamma(hline = Euler) Adding an option to the function curve may be useful: options = c("warn", "silent", "unconnected") This is part of some experiments in math; but that's another topic. For latest version: https://github.com/discoleo/R/blob/master/Math/Integrals.Gamma.Inv.R If you know where the discontinuities are, plot multiple times with the discontinuities as endpoints: plot.gamma = function(xlim = c(-6, -1), ylim = c(-1,3), hline = NULL, n = 1000) { start <- floor(xlim[1]):floor(xlim[2]) end <- start + 1 start[1] <- xlim[1] end[length(end)] <- xlim[2] n <- round(n/length(start)) curve(gamma(x), from = start[1], to = end[1], ylim=ylim, n=n, xlim = xlim) for (i in seq_along(start)[-1]) curve(gamma(x), from = start[i], to = end[i], add = TRUE, n) if( ! is.null(hline)) abline(h = hline, col = "green"); } Euler = 0.57721566490153286060651209008240243079; plot.gamma(hline = Euler) If you don't know where the discontinuities are, it would be much harder, because discontinuities can be hard to detect unless the jumps are really big. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Packages sometimes don't update, but no error or warning is thrown
I think you should ask more from the BioC folks, or do more digging yourself. At a minimum we would need to know what arguments were used in the call that failed before we could help you with this. So if this ever happens again, here's what you can do: Run debug(install.packages), then the call to BiocManager::install. It will break to the debugger when install.packages is called. It will print the whole source of install.packages which is quite long, but at the very top it will show something like debugging in: install.packages(pkgs = x) The "install.packages(pkgs = x)" will be the call from whatever function calls install.packages. The arguments shown may be constants or variables like x; the argument names may or may not be shown, depending on the Bioconductor code. If they are variables, they are in the scope of the caller, not install.packages, whereas the argument name "pkgs" would be in scope and you could print it. Record all the arguments that were passed, then quit using Q. Now run undebug(install.packages), and re-run the install.packages() call from the command line, substituting the variables you recorded. If that shows the same problems as when called from BiocManager::install, show us the log of what happened. If not, it's a Bioconductor issue. Duncan Murdoch On 13/02/2024 5:07 a.m., gernop...@gmx.net wrote: Yes you're right that it started as an Bioconductor issue. The reason I am writing it here, if because of one of the core members of the Bioconductor project stated this: "(...) But anyway, it's almost certainly an install.packages issue rather than BiocManager::install, so you might check over at r-help@r-project.org." It's hard to give an explicit example here since it's always a bit time dependent, when and if this happens. And "unfortunately", right now all packages can be updated, but I'll come back to this as soon as I experience it again. It's more of a general feature request then a help request, but as you say "In my experience update.packages() asks whether you want the source or binary install and respects your choice." However, at least for me, it does not do this anymore, but simply silently fails to update those packages. The Bioconductor thread is the most informative for this (https://support.bioconductor.org/p/9156283 <https://support.bioconductor.org/p/9156283/#9156308>) in case anyone wants to check the situation in more detail. Philipp *Gesendet:* Dienstag, 13. Februar 2024 um 10:53 Uhr *Von:* "Duncan Murdoch" *An:* "R Project Help" *Betreff:* [R] Packages sometimes don't update, but no error or warning is thrown Those three references are about RStudio and Bioconductor (or at least they start out that way, I didn't read through the long threads). Neither of those is relevant here, but from my quick scan it appears the issue is that those systems detect a package in source form is available, then install an older binary instead. If you have an example where update.packages() does this, that would be on topic on this list. Please post just that here: your calls, and all the output you received. In my experience update.packages() asks whether you want the source or binary install and respects your choice. Duncan Murdoch On 13/02/2024 3:59 a.m., gernophil--- via R-help wrote: > Hey everyone, > > this question is related to this (https://community.rstudio.com/t/packages-are-not-updating/166214/3 <https://community.rstudio.com/t/packages-are-not-updating/166214/3>), this (https://www.biostars.org/p/9586316/#9586323 <https://www.biostars.org/p/9586316/#9586323>) and this (https://support.bioconductor.org/p/9156283/#9156308 <https://support.bioconductor.org/p/9156283/#9156308>). The two latter ones are pots from myself. > > To sum it up: If I am updating packages (be it via Bioconductor or CRAN) some packages simply don’t update, but they also don’t throw any warning or error that they have not been updated. The reason behind this is most likely that there is an update, but it’s not yet available as a binary – in my case as a "mac.binary.big-sur-arm64", since I am on Apple Silicon. My pkgType is set to "both" (default), but my .Platform$pkgType is "mac.binary.big-sur-arm64" (also default). > > If the system shows an update is available and I click update (or update via install.packages()), but the package will not be updated, I would expect any kind of message that the package will not be updated, since no newer binary is available or a prompt, if I want to compile from source. However, the only message I get is: > ``` > trying URL '' > Content type 'application/x-gzip' length XXX bytes (X.X MB) > == > downloaded X.X MB > > > The downloaded binary packages are
[R] Packages sometimes don't update, but no error or warning is thrown
Those three references are about RStudio and Bioconductor (or at least they start out that way, I didn't read through the long threads). Neither of those is relevant here, but from my quick scan it appears the issue is that those systems detect a package in source form is available, then install an older binary instead. If you have an example where update.packages() does this, that would be on topic on this list. Please post just that here: your calls, and all the output you received. In my experience update.packages() asks whether you want the source or binary install and respects your choice. Duncan Murdoch On 13/02/2024 3:59 a.m., gernophil--- via R-help wrote: Hey everyone, this question is related to this (https://community.rstudio.com/t/packages-are-not-updating/166214/3), this (https://www.biostars.org/p/9586316/#9586323) and this (https://support.bioconductor.org/p/9156283/#9156308). The two latter ones are pots from myself. To sum it up: If I am updating packages (be it via Bioconductor or CRAN) some packages simply don’t update, but they also don’t throw any warning or error that they have not been updated. The reason behind this is most likely that there is an update, but it’s not yet available as a binary – in my case as a "mac.binary.big-sur-arm64", since I am on Apple Silicon. My pkgType is set to "both" (default), but my .Platform$pkgType is "mac.binary.big-sur-arm64" (also default). If the system shows an update is available and I click update (or update via install.packages()), but the package will not be updated, I would expect any kind of message that the package will not be updated, since no newer binary is available or a prompt, if I want to compile from source. However, the only message I get is: ``` trying URL '' Content type 'application/x-gzip' length XXX bytes (X.X MB) == downloaded X.X MB The downloaded binary packages are in /var/folders/ws/XXX/T//YYY/downloaded_packages ``` To see, if the package was actually updated, I have to check for updates again (or check the version of the installed package). Is this the expected behavior and if so, why? (Also, why is there a double slash in the path to the downloaded packages?) Thanks for your help. Best, Philipp __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line
That looks to me like a bug, but I don't use Windows any more, so I won't offer to try to fix it for you. In fact I don't think Rterm has many users at all: most Windows users probably use RStudio or one of the other graphical front ends (Visual Studio, Emacs, Rgui, etc.) So maybe you can track down the issue, or someone else will try. Or maybe you'll just have to avoid triggering the bug (if it really is one). Duncan Murdoch On 09/02/2024 10:03 a.m., Iago Giné Vázquez wrote: Yes, indeed, I am talking about Rterm in Windows. Iago *De:* Duncan Murdoch *Enviat el:* divendres, 9 de febrer de 2024 13:50 *Per a:* Iago Giné Vázquez *Tema:* Re: [R] Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line On 09/02/2024 6:25 a.m., Iago Giné Vázquez wrote: Hi all, I cite from README.Rterm ^D, DEL : Delete the character under the cursor. That is the general behaviour, but when there is no character (neither under the cursor nor at its left), pressing the Delete key suggests closing the R terminal. Is there any (configurable) way to avoid this behaviour? Are you talking about rterm in Windows, or which front end? Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R interpreting numeric field as a boolean field
If you are using the read_excel() function from the readxl package, then there's an argument named col_types that lets you specify the types to use. You could specify col_types = "numeric" to read all columns as numeric columns. If some columns are different types, you should specify a vector of type names, with one entry per column. Allowable names are "skip", "guess", "logical", "numeric", "date", "text" or "list". You'll have to read the docs to find out what some of those do. Duncan Murdoch On 30/01/2024 1:40 p.m., Paul Bernal wrote: Dear friend Duncan, Thank you so much for your kind reply. Yes, that is exactly what is happening, there are a lot of NA values at the start, so R assumes that the field is of type boolean. The challenge that I am facing is that I want to read into R an Excel file that has many sheets (46 in this case) but I wanted to combine all 46 sheets into a single dataframe (since the columns are exactly the same for all 46 sheets). The rio package does this nicely, the problem is that, once I have the full dataframe (which amounts to roughly 2.98 million rows total), I cannot change the data type from boolean to numeric. I tried doing dataset$my_field = as.numeric(dataset$my_field), I also tried to do dataset <- dataset[complete.cases(dataset), ], didn't work either. The only thing that worked for me was to take a single sheed and through the read_excel function use the guess_max parameter and set it to a sufficiently large number (a number >= to the total amount of the full merged dataset). I want to automate the merging of the N number of Excel sheets so that I don't have to be manually doing it. Unless there is a way to accomplish something similar to what rio's package function import_list does, that is able to keep the field's numeric data type nature. Cheers, Paul El mar, 30 ene 2024 a las 12:23, Duncan Murdoch (mailto:murdoch.dun...@gmail.com>>) escribió: On 30/01/2024 11:10 a.m., Paul Bernal wrote: > Dear friends, > > Hope you are doing well. I am currently using R version 4.3.2, and I have a > .xlsx file that has 46 sheets on it. I basically combined all 46 sheets > and read them as a single dataframe in R using package rio. > > I read a solution using package readlx, as suggested in a StackOverflow > discussion as follows: > df <- read_excel(path = filepath, sheet = sheet_name, guess_max = 10). > Now, when you have so many sheets (46 in my case) in an Excel file, the rio > methodology is more practical. > > This is what I did: > path = > "C:/Users/myuser/Documents/DataScienceF/Forecast_and_Econometric_Analysis_FIGI > (4).xlsx" > figidat = import_list(path, rbind = TRUE) #here figidat refers to my dataset > > Now, it successfully imports and merges all records, however, some fields > (despite being numeric), R interprets as a boolean field. > > Here is the structure of the field that is causing me problems (I apologize > for the length): > structure(list(StoreCharges = c(NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ... > FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NA, NA, > FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, > FALSE, FALSE, FALSE)), class = c("tbl_df", "tbl", "data.frame" > ), row.names = c(NA, -7033L)) > > As you can see, when I do the dput, it gives me a bunch of TRUE and FALSE > values, when in reality I have records with value $0, records with amounts >> $0 and also a bunch of blank records. > > Any help will be greatly appreciated. I don't know how read_excel() determines column types, but some functions look only at the first n rows to guess the type. It appears you have a lot of NA values at the start. That is a logical value, so that might be what is going wrong. In read.table() and related functions, you can specify the types of column explicitly. It sounds as though that's what you should do if read_excel() offers that
Re: [R] R interpreting numeric field as a boolean field
On 30/01/2024 11:10 a.m., Paul Bernal wrote: Dear friends, Hope you are doing well. I am currently using R version 4.3.2, and I have a .xlsx file that has 46 sheets on it. I basically combined all 46 sheets and read them as a single dataframe in R using package rio. I read a solution using package readlx, as suggested in a StackOverflow discussion as follows: df <- read_excel(path = filepath, sheet = sheet_name, guess_max = 10). Now, when you have so many sheets (46 in my case) in an Excel file, the rio methodology is more practical. This is what I did: path = "C:/Users/myuser/Documents/DataScienceF/Forecast_and_Econometric_Analysis_FIGI (4).xlsx" figidat = import_list(path, rbind = TRUE) #here figidat refers to my dataset Now, it successfully imports and merges all records, however, some fields (despite being numeric), R interprets as a boolean field. Here is the structure of the field that is causing me problems (I apologize for the length): structure(list(StoreCharges = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ... FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NA, NA, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)), class = c("tbl_df", "tbl", "data.frame" ), row.names = c(NA, -7033L)) As you can see, when I do the dput, it gives me a bunch of TRUE and FALSE values, when in reality I have records with value $0, records with amounts $0 and also a bunch of blank records. Any help will be greatly appreciated. I don't know how read_excel() determines column types, but some functions look only at the first n rows to guess the type. It appears you have a lot of NA values at the start. That is a logical value, so that might be what is going wrong. In read.table() and related functions, you can specify the types of column explicitly. It sounds as though that's what you should do if read_excel() offers that as a possibility. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] DescTools::Quantile
On 26/01/2024 10:38 a.m., Michael Meyer via R-help wrote: Greetings, I am having a problem with DescTools::Quantile (a function computing quantiles from weighted samples): # these sum to one probWeights = c( 0.0043, 0.0062, 0.0087, 0.0119, 0.0157, 0.0204, 0.0257, 0.0315, 0.0378, 0.0441, 0.0501, 0.0556, 0.06, 0.0632, 0.0648, 0.0648, 0.0632, 0.06, 0.0556, 0.0501, 0.0441, 0.0378, 0.0315, 0.0257, 0.0204, 0.0157, 0.0119, 0.0087, 0.0062, 0.0043 ) x = seq(-100,100,length.out=length(probWeights)) qtls <- DescTools::Quantile(x, weights=probWeights, probs=c(0.1,0.9)) cat("\nQuantiles:\n") print(qtls) Both quantiles are equal to 100! Is this function working or am I not using it correctly? There's an obvious bug in that function: n <- sum(weights) # this sets n to 1 in your data ord <- 1 + (n - 1) * probs # This sets ord to c(1,1) low <- pmax(floor(ord), 1) high <- pmin(low + 1, n) ord <- ord%%1 allq <- approx(cumsum(weights), x, xout = c(low, high), method = "constant", f = 1, rule = 2)$y k <- length(probs) qs <- (1 - ord) * allq[1:k] + ord * allq[-(1:k)] This bug was reported on the package website 6 months ago (https://github.com/AndriSignorell/DescTools/issues/123), and hasn't been addressed. I'd suggest the best action is to find a different package. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Strange results : bootrstrp CIs
On 13/01/2024 8:58 p.m., Rolf Turner wrote: On Sat, 13 Jan 2024 17:59:16 -0500 Duncan Murdoch wrote: My guess is that one of the bootstrap samples had a different selection of countries, so factor(Country) had different levels, and that would really mess things up. You'll need to decide how to handle that: If you are trying to estimate the coefficient for Italy in a sample that contains no data from Italy, what should the coefficient be? Perhaps NA? Ben Bolker conjectured that boot() might be able to handle this. Getting the NAs into the coefficients is a bit of a fag, but. I tried: My question was really intended as a statistical question. From a statistical perspective, if I have a sampling scheme that sometimes generates sample size 0, should my CI be (-Inf, Inf) for high enough confidence level? A Bayesian might say that inference should be entirely based on the prior in the case of no relevant data. You could get similar numerical results by adding some fake data to every bootstrap sample, e.g. a single weighted observation for each country at your prior mean for that country, with weight chosen to match the strength of the prior. But Bayesian methods don't give confidence intervals, they give credible intervals, and those aren't the same thing even if they are sometimes numerically similar. Duncan Murdoch func <- function(data, idx) { clyde <- coef(lm(Score~ Time + factor(Country),data=data)) ccc <- coef(lm(Score~ Time + factor(Country),data=data[idx,])) urk <- rep(NA,length(clyde)) names(urk) <-names(clyde) urk[names(ccc)] <- ccc urk } It produced a result: set.seed(42) B= boot(e, func, R=1000) B ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = e, statistic = func, R = 1000) Bootstrap Statistics : original biasstd. error t1* 609.62500 3.620405295.39452 t2* -54.81250 -1.662470436.32911 t3* -41.3 -2.7337992 100.72113 t4* -96.0 -1.099571899.78864 t5* -126.0 -0.654888663.47076 t6* -26.3 -1.651668387.80483 t7* -15.7 -0.839117091.72467 t8* -21.7 -5.454401383.69211 t9* 18.3 -0.771100185.57278 However I have no idea if the result is correct, or even meaningful. I have no idea what I'm doing. Just hammering and hoping. ️ cheers, Rolf __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Strange results : bootrstrp CIs
Sorry, didn't cc this to the list. Forwarded Message Subject: Re: [R] Strange results : bootrstrp CIs Date: Sat, 13 Jan 2024 17:37:19 -0500 From: Duncan Murdoch To: varin sacha You can debug things like this by setting options(error = recover). That will drop into the debugger when the error occurs. Examine t.star, r, and res[[r]] and you will likely see what the problem was. My guess is that one of the bootstrap samples had a different selection of countries, so factor(Country) had different levels, and that would really mess things up. You'll need to decide how to handle that: If you are trying to estimate the coefficient for Italy in a sample that contains no data from Italy, what should the coefficient be? (This is easier for Bayesians to handle: we don't need data!) Duncan On 13/01/2024 5:22 p.m., varin sacha via R-help wrote: Dear Duncan, Dear Ivan, I really thank you a lot for your response. So, if I correctly understand your answers the problem is coming from this line: coef(lm(Score~ Time + factor(Country)),data=data[idx,]) This line should be: coef(lm(Score~ Time + factor(Country),data=data[idx,])) If yes, now I get an error message (code here below)! So, it still does not work. Error in t.star[r, ] <- res[[r]] : number of items to replace is not a multiple of replacement length ## Score=c(345,564,467,675,432,346,476,512,567,543,234,435,654,411,356,658,432,345,432,345, 345,456,543,501) Country=c("Italy", "Italy", "Italy", "Turkey", "Turkey", "Turkey", "USA", "USA", "USA", "Korea", "Korea", "Korea", "Portugal", "Portugal", "Portugal", "UK", "UK", "UK", "Poland", "Poland", "Poland", "Austria", "Austria", "Austria") Time=c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3) e=data.frame(Score, Country, Time) library(boot) func= function(data, idx) { coef(lm(Score~ Time + factor(Country),data=data[idx,])) } B= boot(e, func, R=1000) boot.ci(B, index=2, type="perc") # Le samedi 13 janvier 2024 à 21:56:58 UTC+1, Ivan Krylov a écrit : В Sat, 13 Jan 2024 20:33:47 + (UTC) varin sacha via R-help пишет: coef(lm(Score~ Time + factor(Country)),data=data[idx,]) Wrong place for the data=... argument. You meant to give it to lm(...), but in the end it went to coef(...). Without the data=... argument, the formula passed to lm() picks up the global variables inherited by the func() closure. Unfortunately, S3 methods really do have to ignore extra arguments they don't understand if the class is to be extended, so coef.lm isn't allowed to complain to you about it. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Strange results : bootrstrp CIs
On 13/01/2024 3:33 p.m., varin sacha via R-help wrote: Score=c(345,564,467,675,432,346,476,512,567,543,234,435,654,411,356,658,432,345,432,345, 345,456,543,501) Country=c("Italy", "Italy", "Italy", "Turkey", "Turkey", "Turkey", "USA", "USA", "USA", "Korea", "Korea", "Korea", "Portugal", "Portugal", "Portugal", "UK", "UK", "UK", "Poland", "Poland", "Poland", "Austria", "Austria", "Austria") Time=c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3) e=data.frame(Score, Country, Time) library(boot) func= function(data, idx) { coef(lm(Score~ Time + factor(Country)),data=data[idx,]) } B= boot(e, func, R=1000) boot.ci(B, index=2, type="perc") Your function ignores the data, because it passes data[idx,] to coef(), not to lm(). coef() ignores it. So the function is using the global variables you created earlier, not the ones in e. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Truncated plots
On 09/01/2024 11:42 a.m., Nick Wray wrote: Hello As a postgrad I have been helping an undergraduate student with R coding but she has a problem with R studio on her laptop which I can't fix - basically when she runs a plot it appears without a y axis label with the black line plot frame hard against the plot window and the bottom of the plot, where you would expect to see the horizontal axis and the x axis label etc is completely "chopped off" by the bottom edge of the R studio interface window. I can't find anything on the net detailing this problem - can anyone help? I have a screenshot which could email if anyone needs to see what it looks like. Does this happen only in RStudio? She can run `pdf("somefile.pdf")` before plotting and `dev.off()` after to save the results to a PDF file instead. If the problem only occurs in RStudio, then you should probably contact Posit or one of their community support groups about it. If it happens in other devices too: is she using base graphics, or ggplot2, or something else? If she's using base graphics, take a look at `par("mar")`. That gives the size of the margins measured in lines of text; they are in the order bottom, left, top, right, with default value `c(5.1, 4.1, 4.1, 2.1)`. Perhaps she has set the 2nd entry to zero. I'm sure there's something similar in ggplot2 and other graphics systems, but I don't know what it would be. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting based a custom sorting function
On 14/12/2023 11:37 a.m., Martin Morgan wrote: In the spirit of 'advent of code', maybe it is better to exploit the features of the particular language you've chosen? Then the use of factors seems very relevant. value_levels <- c("Small", "Medium", "Large") df <- data.frame( person = c("Alice", "Bob", "Bob", "Charlie"), value = factor( c("Medium", "Large", "Small", "Large"), levels = value_levels ) ) df[with(df, order(person, value)),] Likely this is more efficient than the hints of your existing solution, because it will act on vectors rather than iterating through individual elements of the 'person' and 'value' vectors. For a more general solution, I don't think I'd follow the low-level approach Duncan suggests (maybe see also ?Math for S3 generics), but rather define a class (e.g., that requires vectors person and value) and implement a corresponding `xtfrm()` method. I'd agree, in cases where it's feasible to implement one. But there are cases where the pairwise comparison is obvious, while the numeric conversion isn't. A simple one would be a list of string vectors of different lengths, where you want to sort lexicographically. Duncan Have fun with the remainder of the advent! Another Martin From: R-help on behalf of Martin Møller Skarbiniks Pedersen Date: Thursday, December 14, 2023 at 6:42 AM To: R mailing list Subject: Re: [R] Sorting based a custom sorting function On Thu, 14 Dec 2023 at 12:02, Duncan Murdoch wrote: class(df$value) <- "sizeclass" `>.sizeclass` <- function(left, right) custom_sort(unclass(left), unclass(right)) == 1 `==.sizeclass` <- function(left, right) custom_sort(unclass(left), unclass(right)) == 0 `[.sizeclass` <- function(x, i) structure(unclass(x)[i], class="sizeclass") df[order(df$value),] All the "unclass()" calls are needed to avoid infinite recursion. For a more complex kind of object where you are extracting attributes to compare, you probably wouldn't need so many of those. Great! Just what I need. I will create a class and overwrite > and ==. I didn't know that order() used these exact methods. My best solution was something like this: quicksort <- function(arr, compare_func) { if (length(arr) <= 1) { return(arr) } else { pivot <- arr[[1]] less <- arr[-1][compare_func(arr[-1], pivot) <= 0] greater <- arr[-1][compare_func(arr[-1], pivot) > 0] return(c(quicksort(less, compare_func), pivot, quicksort(greater, compare_func))) } } persons <- c("alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliett", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "x-ray", "yankee", "zulu") quicksort(persons, function(left, right) { nchar(left) - nchar(right) }) Regards Martin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting based a custom sorting function
On 14/12/2023 3:00 a.m., Martin Møller Skarbiniks Pedersen wrote: Hi, I need to sort a data.frame based on a custom sorting function. It is easy in many languages but I can't find a way to do it in R. In many cases I could just use an ordered factor but my data.frame contains poker hands and I need to rank these hands. I already got a function that compares two hands. Here is a MRE (Minimal, Reproducible Example): df <- data.frame(person = c("Alice", "Bob", "Charlie"), value = c("Medium", "Small", "Large")) # 0 means equal, -1 means left before right, 1 means right before left custom_sort <- function(left, right) { if (left == right) return(0) if (left == "Small") return(-1) if (left == "Medium" & right == "Large") return(-1) return(1) } # sort df according to custom_soft # expect output is a data.frame: # name size # 1 Bob Medium # 2 Alice Small # 3 Charlie Large In this simple case I can just use an ordered factor but what about the poker hands situation? The general way in base R is to put the objects in a vector (which might be a list if they are complex objects), assign a class to that vector, and define either an xtfrm method or methods for ==, >, is.na, and extraction for that vector. The xtfrm method is basically the same as using an ordered factor, so I'll skip that, and show you the other way: For your example, you could do it like this: class(df$value) <- "sizeclass" `>.sizeclass` <- function(left, right) custom_sort(unclass(left), unclass(right)) == 1 `==.sizeclass` <- function(left, right) custom_sort(unclass(left), unclass(right)) == 0 `[.sizeclass` <- function(x, i) structure(unclass(x)[i], class="sizeclass") df[order(df$value),] All the "unclass()" calls are needed to avoid infinite recursion. For a more complex kind of object where you are extracting attributes to compare, you probably wouldn't need so many of those. There are likely other ways to do this in particular packages such as dplyr or data.table. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert character date time to R date-time variable.
On 08/12/2023 4:30 p.m., David Winsemius wrote: On 12/7/23 08:21, Sorkin, John wrote: Colleagues, I have a matrix of character data that represents date and time. The format of each element of the matrix is "2020-09-17_00:00:00" How can I convert the elements into a valid R date-time constant? You will not be able to store these datetime values in an R matrix, at least as class POSIXct. You could with class POSIXlt, but I've not seen it used before but it does appear possible since matrices can contain lists. R matrices do no provide the capability to assign attributes, so only atomic types and lists can be elements. If you wanted to maintain the same structure, your first step might be to coerce to a data.frame and then proceed, or to first construct a vector and then use as the first argument to `matrix`. The general sentiment is correct (it's hard to put POSIXct elements in matrices), but it's not impossible. Almost all R objects can have attributes. For example, m <- matrix(Sys.time(), 2,2) converts the time to a numerical value, but you can view it as a POSIXlt object using class(m) <- c("POSIXct", class(m)) Subsetting works, e.g. m[1,1] is a time, etc. Duncan Murdoch Best; David Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine, University of Maryland School of Medicine; Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center; PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center; Senior Statistician University of Maryland Center for Vascular Research; Division of Gerontology and Paliative Care, 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 Cell phone 443-418-5382 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
On 02/12/2023 5:37 p.m., CALUM POLWART wrote: You could easily omit the Page X of xX, but leave the timestamp Then add Page X of XX programmatically using pdftools or some similar pdf command line tools. You don't need to use command line tools -- I showed how to do it by creating an R Markdown document with each page of the PDF on a numbered page of the result. Here's a minor improvement of my post: --- title: "Numbered" output: pdf_document: extra_dependencies: ["pdfpages", "fancyhdr", "lastpage"] --- \cfoot{Page \thepage\ of \pageref{LastPage}} \addtocounter{page}{-1} \includepdf[pages={1-},pagecommand={\thispagestyle{fancy}}]{Rplots.pdf} This works regardless of the number of pages in Rplots.pdf. Duncan Murdoch On Sat, 2 Dec 2023, 22:35 , wrote: Having read all of the replies, it seems there are solutions for the question and the OP points out that some solutions such as making the document twice will affect the creation date. I suspect the additional time to do so is seconds or at most minutes so it may not be a big deal. But what about the idea of creating a PDF with a placeholder like "Page N of XXX" and after the file has been created, dates and all, perhaps edit it programmatically and replace all instances of XXX with something of the same length like " 23" as there seem to be tools like the pdftools package that let you get the number of pages. I have no idea if some program, perhaps external, can do that and retain the date you want. -Original Message- From: R-help On Behalf Of Dennis Fisher Sent: Friday, December 1, 2023 3:53 PM To: r-help@r-project.org Subject: [R] adding "Page X of XX" to PDFs OS X R 4.3.1 Colleagues I often create multipage PDFs [pdf()] in which the text "Page X" appears in the margin. These PDFs are created automatically using a massive R script. One of my clients requested that I change this to: Page X of XX where XX is the total number of pages. I don't know the number of expected pages so I can't think of any clever way to do this. I suppose that I could create the PDF, find out the number of pages, then have a second pass in which the R script was fed the number of pages. However, there is one disadvantage to this -- the original PDF contains a timestamp on each page -- the new version would have a different timestamp -- so I would prefer to not use this approach. Has anyone thought of some terribly clever way to solve this problem? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] adding "Page X of XX" to PDFs
On 02/12/2023 2:07 p.m., Ben Bolker wrote: Sorry, jumped into the thread too late. (On the other hand, once the document gets complicated enough, it may be worth it in the long run to convert to something that actually has a document-generating back-end, rather than reinventing everything from scratch ...) I agree with that comment. However, if one is stuck with a multipage PDF file, and wants to add page numbering, you could use the LaTeX pdfpages package. For example, this R Markdown document includes all 10 plots from Rplots.pdf on pages with "x of y" page numbering. --- title: "Numbered" output: pdf_document: extra_dependencies: ["pdfpages", "fancyhdr", "lastpage"] --- \cfoot{Page \thepage\ of \pageref{LastPage}} \addtocounter{page}{-1} \includepdf[pages={1-10},pagecommand={\thispagestyle{fancy}}]{Rplots.pdf} It would make more sense to do this in a LaTeX document, but I'm not sure if Dennis knows LaTeX... Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Code editor for writing R code
On 29/11/2023 1:29 p.m., Eric Berger wrote: Bert, Posit (formerly RStudio) has moved from RMarkdown to Quarto. They still support RMarkdown but major new features will be in Quarto. For new users a better choice would be Quarto. See https://quarto.org/docs/faq/rmarkdown.html I'm not sure about that advice. Quarto has some bad design choices. For example, these lines: https://github.com/quarto-dev/quarto-cli/blob/3c9950947871ceafa54de909b15077cd54e27efe/src/resources/rmd/patch.R#L159-L184 have them faking S3 dispatch, but doing it really badly. They worked around an issue I reported last year (https://github.com/quarto-dev/quarto-cli/issues/1800), but with a design like that, there will be other issues. Secondly, the OP stated he was using the VS-Code IDE, so there is no reason to point him to the Posit/RStudio IDE for this functionality which VS-Code supports very well (as I noted in my response.) The original question did ask for recommendations for a different editor. Duncan Murdoch Best, Eric On Wed, Nov 29, 2023 at 6:55 PM Christofer Bogaso wrote: Hi Sergei, Where can I find TeX Comments extension in VS Code? On Wed, Nov 29, 2023 at 9:34 PM Sergei Ko wrote: TeX Comments extension in VS Code Sent from my phone Original message From: Christofer Bogaso Date: Wed, 29 Nov 2023, 15:57 To: r-help Subject: [R] Code editor for writing R code Hi, Currently I use VS-Code to write codes in R. While it is very good, it does not allow me to write Latex expressions in comments, which I am willing to have to write corresponding mathematical expressions as comments in my code files. Does there exist any Code editor for R, that allows me to write Latex in comments? Any information will be appreciated. Thanks, __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] anyone having trouble accesing CRAN?
Yes, they posted a message about this recently. There's some maintenance happening and CRAN will be unavailable for a while. I can't find that message, but I think it was 2 or 3 days of downtime. Duncan Murdoch On 15/11/2023 2:13 p.m., Christopher W. Ryan via R-help wrote: at https://cran.r-project.org/ I get this error message: = Secure Connection Failed An error occurred during a connection to cran.r-project.org. PR_END_OF_FILE_ERROR Error code: PR_END_OF_FILE_ERROR The page you are trying to view cannot be shown because the authenticity of the received data could not be verified. === Three different browsers, two different devices, two different networks. (The text of the error messages varies.) Anyone seeing similar? Thanks. --Chris Ryan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calling Emacs Lisp Code/Function from R
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, 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 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 guide? Thank you! Iris __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] The argument 'eps.Pvalue' of `printCoefmat()`
On 29/10/2023 3:48 a.m., Shu Fai Cheung wrote: Hi all, Just a minor issue that I am not sure whether this is considered a "bug." It is about the help page. In the help page of printCoefmat(), for the argument 'eps.Pvalue', the description is as below: number, .. I have to read the source to figure out that this argument is to be used by format.pval(). Maybe the description of 'eps.Pvalue' can be revised to refer users to the help page of format.pval()? That looks like an oversight by the author of the help page. It's been there for at least 20 years! Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Tagged] Re: col.names in as.data.frame() ?
On 28/10/2023 4:45 p.m., Bert Gunter wrote: Jeff, et. al. : but ... Note that as.data.frame() *already* changes the matrix object by adding column names of *its own choosing* when the matrix has none. So the issue here is not *whether* col names should be added, but *what*/*how* they should be. Unless you wish to extend your criticism to the current version for its failure to adhere to your proscription. Dataframes have to have column names. The function isn't modifying the object any more than it has to. Duncan Murdoch Cheers, Bert On Sat, Oct 28, 2023 at 11:55 AM Jeff Newmiller via R-help < r-help@r-project.org> wrote: as.data.frame is a _converter_, while data.frame is a _constructor_. Changing the object contents is not what a conversion is for. On October 28, 2023 11:39:22 AM PDT, Boris Steipe < boris.ste...@utoronto.ca> wrote: Thanks Duncan and Avi! That you could use NULL in a matrix() dimnames = list(...) argument wasn't clear to me. I thought that would be equivalent to a one-element list - and thereby define rownames. So that's good to know. The documentation could be more explicit - but it is probably more work to do that than just patch the code to honour a col.names argument. (At least I can't see a reason not to.) Thanks again! :-) On Oct 28, 2023, at 14:24, avi.e.gr...@gmail.com wrote: Борис, Try this where you tell matrix the column names you want: nouns <- as.data.frame( matrix(c( "gaggle", "geese", "dule", "doves", "wake", "vultures" ), ncol = 2, byrow = TRUE, dimnames=list(NULL, c("collective", "category" Result: nouns collective category 1 gagglegeese 2 duledoves 3 wake vultures The above simply names the columns earlier when creating the matrix. There are other ways and the way you tried LOOKS like it should work but fails for me with a message about it weirdly expecting three rows versus two which seems to confuse rows and columns. My version of R is recent and I wonder if there is a bug here. Consider whether you really need the data.frame created in a single statement or can you change the column names next as in: nouns V1 V2 1 gagglegeese 2 duledoves 3 wake vultures colnames(nouns) [1] "V1" "V2" colnames(nouns) <- c("collective", "category") nouns collective category 1 gagglegeese 2 duledoves 3 wake vultures Is there a known bug here or is the documentation wrong? -Original Message- From: R-help On Behalf Of Boris Steipe Sent: Saturday, October 28, 2023 1:54 PM To: R. Mailing List Subject: [R] col.names in as.data.frame() ? I have been trying to create a data frame from some structured text in a single expression. Reprex: nouns <- as.data.frame( matrix(c( "gaggle", "geese", "dule", "doves", "wake", "vultures" ), ncol = 2, byrow = TRUE), col.names = c("collective", "category") ) But ... : str(nouns) 'data.frame': 3 obs. of 2 variables: $ V1: chr "gaggle" "dule" "wake" $ V2: chr "geese" "doves" "vultures" i.e. the col.names argument does nothing. From my reading of ?as.data.frame, my example should have worked. I know how to get the required result with colnames(), but I would like to understand why the idiom as written didn't work, and how I could have known that from the help file. Thanks! Boris __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducibl
Re: [R] col.names in as.data.frame() ?
Sent a slightly shorter version of this to your email, this one is to the list: On 28/10/2023 1:54 p.m., Boris Steipe wrote: > > I have been trying to create a data frame from some structured text in a single expression. Reprex: > > > > nouns <- as.data.frame( > >matrix(c( > > "gaggle", > > "geese", > > > > "dule", > > "doves", > > > > "wake", > > "vultures" > >), ncol = 2, byrow = TRUE), > >col.names = c("collective", "category") > > ) > > You are calling it on a matrix, so the as.data.frame.matrix method is what matters. It doesn't have a col.names argument, only row.names. The docs are vague about what ... does, but if you look at the method, you can see any unnamed arguments are ignored completely. If you want to specify the column names in a single call, you'll need to put them in the matrix, e.g. as.data.frame( matrix(c( "gaggle", "geese", "dule", "doves", "wake", "vultures" ), ncol = 2, byrow = TRUE, dimnames = list(NULL, c("collective", "category")) ) ) Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bug in print for data frames?
On 25/10/2023 2:18 a.m., Christian Asseburg wrote: Hi! I came across this unexpected behaviour in R. First I thought it was a bug in the assignment operator <- but now I think it's maybe a bug in the way data frames are being printed. What do you think? Using R 4.3.1: x <- data.frame(A = 1, B = 2, C = 3) y <- data.frame(A = 1) x A B C 1 1 2 3 x$B <- y$A # works as expected x A B C 1 1 1 3 x$C <- y[1] # makes C disappear x A B A 1 1 1 1 str(x) 'data.frame': 1 obs. of 3 variables: $ A: num 1 $ B: num 1 $ C:'data.frame': 1 obs. of 1 variable: ..$ A: num 1 Why does the print(x) not show "C" as the name of the third element? I did mess up the data frame (and this was a mistake on my part), but finding the bug was harder because print(x) didn't show the C any longer. y[1] is a dataframe with one column, i.e. it is identical to y. To get the result you expected, you should have used y[[1]], to extract column 1. Since dataframes are lists, you can assign them as columns of other dataframes, and you'll create a single column in the result whose rows are the columns of the dataframe you're assigning. This means that x$C <- y[1] replaces the C column of x with a dataframe. It retains the name C (you can see this if you print names(x) ), but since the column contains a dataframe, it chooses to use the column name of y when printing. If you try x$D <- x you'll see it generate new names when printing, but the names within x remain as A, B, C, D. This is a situation where tibbles do a better job than dataframes: if you created x and y as tibbles instead of dataframes and executed your code, you'd see this: library(tibble) x <- tibble(A = 1, B = 2, C = 3) y <- tibble(A = 1) x$C <- y[1] x #> # A tibble: 1 × 3 #> A B C$A #> #> 1 1 2 1 Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error running gee function. I neither understand the error message, nor know what needs to be done the get the gee to run
Actually a better solution would be to make PID into a factor. They can always be coerced to a number, but will display with your meaningful labels. Duncan Murdoch On 25/10/2023 3:38 p.m., Duncan Murdoch wrote: I don't see it documented, but it appears that the gee() function assumes the id variable can be coerced to a number. Your ids are in PID, and are strings like "HIPS004", etc. Change that to "004" or a numeric 4 and the error goes away. Duncan Murdoch On 25/10/2023 3:23 p.m., Sorkin, John wrote: Colleagues, I am receiving several error messages from the gee function. I don't understand the ides the error messages are trying to impart, and I don't know how to debug or correct the error. The error messages follow: fitgee <- gee(HipFlex ~ StepHeight,data=datashort,id=PID,corstr="exchangeable",na.action=na.omit) Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27 running glm to get initial regression estimate (Intercept) StepHeight 1.400319 58.570236 Error in gee(HipFlex ~ StepHeight, data = datashort, id = PID, corstr = "exchangeable", : NA/NaN/Inf in foreign function call (arg 3) In addition: Warning message: In gee(HipFlex ~ StepHeight, data = datashort, id = PID, corstr = "exchangeable", : NAs introduced by coercion Of note, when the analysis is run using lm, there is no problem. My fully data and code follow: Thank you, John CODE: if (!require(gee)) {install.packages("gee")} library(gee) datashort <- structure(list(HipFlex = c(1.95, 2.07, 1.55, 0.44, 0.23, 0.41, 0.22, 4.61, 10.02, 1.08, 1.43, 1.82, 0.34, 0.77, 0.22, 1.06, 0.13, 0.36, 2.84, 5.2, 12.27, 1.37, 2.33, 3.48, 4.76, 1.92, 2.09, 4.67, 2.94, 0.75, 0.11, 3.56, 1.63, 0.8, 1.54, 5.06, NA,5.41, 6.18, 3.75, 3.12, 17.43, 3.18, 0.85, 14.54, 14.34, 21.92, 4.91, 1.52, 0.38, 0.43, 0.47, 0.56, 6.4, 12.4, 3.98, 0.57, 1.84, 12.06, 0.45, 8.16, 0.02, 0,0.05, 0.52, 0.11, 0.48, 1.5, 3.29, 2.58, 2.07, 6.06, 1.46, 1.06, 3.82, 1.09, 2.86, 3.47, 2.22, 1.89, NA, 3.48, 6.38, 3.58, 1.83, 2.8, 8.28, 7.15, 4.77, 4.93, 0, 0.11, 1.99, 2.01, 2.3, 1.24, 1.33, 2, 1.01), PID = c("HIPS004", "HIPS004", "HIPS005", "HIPS005", "HIPS005", "HIPS006", "HIPS006", "HIPS008", "HIPS010", "HIPS024", "HIPS024", "HIPS024", "HIPS025", "HIPS028", "HIPS028", "HIPS030", "HIPS030", "HIPS030", "HIPS035", "HIPS035", "HIPS035", "HIPS036", "HIPS036", "HIPS037", "HIPS044", "HIPS047", "HIPS047", "HIPS056", "HIPS056", "HIPS057", "HIPS057", "HIPS057", "HIPS058", "HIPS059", "HIPS059", "HIPS061", "HIPS062", "HIPS062", "HIPS062", "HIPS064", "HIPS074", "HIPS079", "HIPS084", "HIPS089", "HIPS090", "HIPS090", "HIPS090", "HIPS091", "HIPS091", "HIPS092", "HIPS092", "HIPS092", "HIPS001", "HIPS001", "HIPS001", "HIPS004", "HIPS004", "HIPS004", "HIPS005", "HIPS005", "HIPS005", "HIPS006", "HIPS006", "HIPS008", "HIPS022", "HIPS024", "HIPS028", "HIPS030", "HIPS035", "HIPS036", "HIPS036", "HIPS039", "HIPS044", "HIPS047", "HIPS051", "HIPS056", "HIPS058", "HIPS058", "HIPS059", "HIPS059", "HIPS062", "HIPS062", "HIPS062", "HIPS069", "HIPS069", "HIPS071", "HIPS074", "HIPS079", "HIPS084", "HIPS084", "HIPS085", "HIPS089", "HIPS090", "HIPS091", "HIPS091", "HIPS091", "HIPS092", "HIPS092", "HIPS093"), StepHeight = c(0.005, 0.008, 0.072, 0.003, 0.014, 0.01, 0.027, 0.074, 0.128, 0.048, 0.036, 0.024, 0.021, 0.026, 0.03, 0.004, 0.006, 0.006, 0.011, 0.006, 0.053, 0.028, 0.073, 0.041, 0.005, 0.007, 0.013, 0.012, 0.021, 0.053, 0.013, 0.071, 0.012, 0.016, 0.023, 0.024, 0.011, 0.019, 0.014, 0.022, 0.011, 0.129, 0.03, 0.012, 0.062, 0.145, 0.077, 0.028, 0.006, 0.019, 0.008, 0.006, 0.034, 0.109, 0.09, 0.005, 0.016, 0.005, 0.257, 0.011, 0.205, 0.01, 0.017, 0.039, 0.01, 0.016, 0.043, 0.004, 0.008, 0.04, 0.068, 0.006, 0.008, 0.005, 0.097, 0.015, 0.016, 0.01, 0.021,
Re: [R] Error running gee function. I neither understand the error message, nor know what needs to be done the get the gee to run
I don't see it documented, but it appears that the gee() function assumes the id variable can be coerced to a number. Your ids are in PID, and are strings like "HIPS004", etc. Change that to "004" or a numeric 4 and the error goes away. Duncan Murdoch On 25/10/2023 3:23 p.m., Sorkin, John wrote: Colleagues, I am receiving several error messages from the gee function. I don't understand the ides the error messages are trying to impart, and I don't know how to debug or correct the error. The error messages follow: fitgee <- gee(HipFlex ~ StepHeight,data=datashort,id=PID,corstr="exchangeable",na.action=na.omit) Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27 running glm to get initial regression estimate (Intercept) StepHeight 1.400319 58.570236 Error in gee(HipFlex ~ StepHeight, data = datashort, id = PID, corstr = "exchangeable", : NA/NaN/Inf in foreign function call (arg 3) In addition: Warning message: In gee(HipFlex ~ StepHeight, data = datashort, id = PID, corstr = "exchangeable", : NAs introduced by coercion Of note, when the analysis is run using lm, there is no problem. My fully data and code follow: Thank you, John CODE: if (!require(gee)) {install.packages("gee")} library(gee) datashort <- structure(list(HipFlex = c(1.95, 2.07, 1.55, 0.44, 0.23, 0.41, 0.22, 4.61, 10.02, 1.08, 1.43, 1.82, 0.34, 0.77, 0.22, 1.06, 0.13, 0.36, 2.84, 5.2, 12.27, 1.37, 2.33, 3.48, 4.76, 1.92, 2.09, 4.67, 2.94, 0.75, 0.11, 3.56, 1.63, 0.8, 1.54, 5.06, NA,5.41, 6.18, 3.75, 3.12, 17.43, 3.18, 0.85, 14.54, 14.34, 21.92, 4.91, 1.52, 0.38, 0.43, 0.47, 0.56, 6.4, 12.4, 3.98, 0.57, 1.84, 12.06, 0.45, 8.16, 0.02, 0,0.05, 0.52, 0.11, 0.48, 1.5, 3.29, 2.58, 2.07, 6.06, 1.46, 1.06, 3.82, 1.09, 2.86, 3.47, 2.22, 1.89, NA, 3.48, 6.38, 3.58, 1.83, 2.8, 8.28, 7.15, 4.77, 4.93, 0, 0.11, 1.99, 2.01, 2.3, 1.24, 1.33, 2, 1.01), PID = c("HIPS004", "HIPS004", "HIPS005", "HIPS005", "HIPS005", "HIPS006", "HIPS006", "HIPS008", "HIPS010", "HIPS024", "HIPS024", "HIPS024", "HIPS025", "HIPS028", "HIPS028", "HIPS030", "HIPS030", "HIPS030", "HIPS035", "HIPS035", "HIPS035", "HIPS036", "HIPS036", "HIPS037", "HIPS044", "HIPS047", "HIPS047", "HIPS056", "HIPS056", "HIPS057", "HIPS057", "HIPS057", "HIPS058", "HIPS059", "HIPS059", "HIPS061", "HIPS062", "HIPS062", "HIPS062", "HIPS064", "HIPS074", "HIPS079", "HIPS084", "HIPS089", "HIPS090", "HIPS090", "HIPS090", "HIPS091", "HIPS091", "HIPS092", "HIPS092", "HIPS092", "HIPS001", "HIPS001", "HIPS001", "HIPS004", "HIPS004", "HIPS004", "HIPS005", "HIPS005", "HIPS005", "HIPS006", "HIPS006", "HIPS008", "HIPS022", "HIPS024", "HIPS028", "HIPS030", "HIPS035", "HIPS036", "HIPS036", "HIPS039", "HIPS044", "HIPS047", "HIPS051", "HIPS056", "HIPS058", "HIPS058", "HIPS059", "HIPS059", "HIPS062", "HIPS062", "HIPS062", "HIPS069", "HIPS069", "HIPS071", "HIPS074", "HIPS079", "HIPS084", "HIPS084", "HIPS085", "HIPS089", "HIPS090", "HIPS091", "HIPS091", "HIPS091", "HIPS092", "HIPS092", "HIPS093"), StepHeight = c(0.005, 0.008, 0.072, 0.003, 0.014, 0.01, 0.027, 0.074, 0.128, 0.048, 0.036, 0.024, 0.021, 0.026, 0.03, 0.004, 0.006, 0.006, 0.011, 0.006, 0.053, 0.028, 0.073, 0.041, 0.005, 0.007, 0.013, 0.012, 0.021, 0.053, 0.013, 0.071, 0.012, 0.016, 0.023, 0.024, 0.011, 0.019, 0.014, 0.022, 0.011, 0.129, 0.03, 0.012, 0.062, 0.145, 0.077, 0.028, 0.006, 0.019, 0.008, 0.006, 0.034, 0.109, 0.09, 0.005, 0.016, 0.005, 0.257, 0.011, 0.205, 0.01, 0.017, 0.039, 0.01, 0.016, 0.043, 0.004, 0.008, 0.04, 0.068, 0.006, 0.008, 0.005, 0.097, 0.015, 0.016, 0.01, 0.021, 0.008, 0.01, 0.006, 0.016, 0.021, 0.012, 0.009, 0.032, 0.055, 0.006, 0.066, 0.018, 0.01, 0.018, 0.017, 0.015, 0.01, 0.017, 0.02, 0.022)), class = "data.frame", row.names = c(4L, 5L, 6L,7L, 8L, 10L, 12L, 14L, 19L, 29L, 30L
Re: [R] running crossvalidation many times MSE for Lasso regression
On 22/10/2023 7:01 p.m., Bert Gunter wrote: No error message shown Please include the error message so that it is not necessary to rerun your code. This might enable someone to see the problem without running the code (e.g. downloading packages, etc.) And it's not necessarily true that someone else would see the same error message. Duncan Murdoch -- Bert On Sun, Oct 22, 2023 at 1:36 PM varin sacha via R-help wrote: Dear R-experts, Here below my R code with an error message. Can somebody help me to fix this error? Really appreciate your help. Best, # MSE CROSSVALIDATION Lasso regression library(glmnet) x1=c(34,35,12,13,15,37,65,45,47,67,87,45,46,39,87,98,67,51,10,30,65,34,57,68,98,86,45,65,34,78,98,123,202,231,154,21,34,26,56,78,99,83,46,58,91) x2=c(1,3,2,4,5,6,7,3,8,9,10,11,12,1,3,4,2,3,4,5,4,6,8,7,9,4,3,6,7,9,8,4,7,6,1,3,2,5,6,8,7,1,1,2,9) y=c(2,6,5,4,6,7,8,10,11,2,3,1,3,5,4,6,5,3.4,5.6,-2.4,-5.4,5,3,6,5,-3,-5,3,2,-1,-8,5,8,6,9,4,5,-3,-7,-9,-9,8,7,1,2) T=data.frame(y,x1,x2) z=matrix(c(x1,x2), ncol=2) cv_model=glmnet(z,y,alpha=1) best_lambda=cv_model$lambda.min best_lambda # Create a list to store the results lst<-list() # This statement does the repetitions (looping) for(i in 1 :1000) { n=45 p=0.667 sam=sample(1 :n,floor(p*n),replace=FALSE) Training =T [sam,] Testing = T [-sam,] test1=matrix(c(Testing$x1,Testing$x2),ncol=2) predictLasso=predict(cv_model, newx=test1) ypred=predict(predictLasso,newdata=test1) y=T[-sam,]$y MSE = mean((y-ypred)^2) MSE lst[i]<-MSE } mean(unlist(lst)) ## __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot to a device and examine the plot?
On 15/10/2023 12:05 p.m., Shu Fai Cheung wrote: Let me clarify my question: plot.new() polygon(c(.5, .5, .75, .8), c(.25, .3, .4, .5)) If the device is an on-screen device, can I check whether a particular area has anything drawn on it, or, to be precise, whether the color of a particular area has all pixels equal to the background color. That is, if the background is white, can I know whether a particular area is white? E.g., in the case above, the area bounded by rect(0, 0, .25, .25) is completely white, while the area bounded by rect(0, 0, .75, .75) is not because part of border of the polygon, black by default, has been drawn in this area. If the device is an image file, then I can check the color of a pixel. I would like to know whether I can do the same with an on-screen device. I think the answer is that you can't do that in general. However, in general you can copy a plot to a different device using dev.copy() and examine it there. It won't be pixel-by-pixel identical, but will contain the same components, likely with slightly different scaling and positioning if the new device isn't the same as the old one. You can also save the commands that drew the plot using recordPlot() and redraw it using replayPlot() (which is essentially what dev.copy() does), but the format of the object saved by recordPlot() is not documented, and is subject to change with R version changes. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Grouping by Date and showing count of failures by date
There's a package called "pivottabler" which exports PivotTable: http://pivottabler.org.uk/reference/PivotTable.html . Duncan Murdoch On 30/09/2023 7:11 a.m., John Kane wrote: To follow up on Rui Barradas's post, I do not think PivotTable is an R command. You may be thinking og the "pivot_longer" and "pivot_wider" functions in the {tidyr} package which is part of {tidyverse}. On Sat, 30 Sept 2023 at 07:03, Rui Barradas wrote: Às 21:29 de 29/09/2023, Paul Bernal escreveu: Dear friends, Hope you are doing great. I am attaching the dataset I am working with because, when I tried to dput() it, I was not able to copy the entire result from dput(), so I apologize in advance for that. I am interested in creating a column named Failure_Date_Period that has the FAILDATE but formatted as _MM. Then I want to count the number of failures (given by column WONUM) and just have a dataframe that has the FAILDATE and the count of WONUM. I tried this: pt <- PivotTable$new() pt$addData(failuredf) pt$addColumnDataGroups("FAILDATE") pt <- PivotTable$new() pt$addData(failuredf) pt$addColumnDataGroups("FAILDATE") pt$defineCalculation(calculationName = "FailCounts", summariseExpression="n()") pt$renderPivot() but I was not successful. Bottom line, I need to create a new dataframe that has the number of failures by FAILDATE, but in -MM format. Any help and/or guidance will be greatly appreciated. Kind regards, Paul __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Hello, No data is attached. Maybe try dput(head(failuredf, 30)) ? And where can we find non-base PivotTable? Please start the scripts with calls to library() when using non-base functionality. Hope this helps, Rui Barradas -- Este e-mail foi analisado pelo software antivírus AVG para verificar a presença de vírus. www.avg.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Odd result
On 23/09/2023 6:55 p.m., Parkhurst, David wrote: With help from several people, I used file.choose() to get my file name, and read.csv() to read in the file as KurtzData. Then when I print KurtzData, the last several lines look like this: 39 5/31/22 16.0 3411.75525 0.0201 0.0214 7.00 40 6/28/22 2:00 PM 0.0 2150.67950 0.0156 0.0294 NA 41 7/25/22 11:00 AM 11.9 1943.5NA NA 0.0500 7.80 42 8/31/22 0220.5NA NA 0.0700 30.50 43 9/28/22 0.067 10.9NA NA 0.0700 10.20 44 10/26/22 0.086 237NA NA 0.1550 45.00 45 1/12/23 1:00 PM 36.2624196NA NA 0.7500 283.50 46 2/14/23 1:00 PM 20.71 55NA NA 0.0500 2.40 47 NA NA NA NA 48 NA NA NA NA 49 NA NA NA NA Then the NA�s go down to one numbered 973. Where did those extras likely come from, and how do I get rid of them? I assume I need to get rid of all the lines after #46, to do calculations and graphics, no? Many Excel spreadsheets have a lot of garbage outside the range of the data. Sometimes it is visible if you know where to look, sometimes it is blank cells. Perhaps at some point you (or the file creator) accidentally entered a number in line 973. Then Excel will think the sheet has 973 lines. I don't know the best way to tell Excel that those lines are pure garbage. That's why old fogies like me recommend that you do as little as possible in Excel. Get the data into a reliable form as soon as possible. Once it is an R dataframe, you can delete lines using negative indices. In this case use fixed <- KurtzData[-(47:nrow(KurtzData)), ] which will create a new dataframe with only rows 1 to 46. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to import an excel data file
On 23/09/2023 3:35 p.m., Ivan Krylov wrote: В Fri, 22 Sep 2023 23:10:58 + "Parkhurst, David" пишет: Its location in my Mac files is DFPfiles/ae/FriendsMonroe/KurtzData.csv How exactly---What _, etc.---do I type with its name in the read_excel() function? In RGui on Windows, file.choose() opens a dialog window letting the user choose a file interactively. Do you get a similar prompt if you run file.choose() in R.app? Choose the file, and it will return a string that would be most certainly suitable for read.csv(), read_excel(), and other functions that accept file paths. file.choose() exists on all platforms. choose.files() only exists on Windows. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] halting with errors
You can use try() or tryCatch(). The former is simpler, the latter is more flexible. For example: result <- try(read_html(“https://timeseries.sepa.org.uk/KiWIS/KiWIS?service=kisters=queryServices=0=getTimeseriesValues_path=1/15016/Q/15m.Cmd=2015-01-01=2015-01-31=Timestamp,Value,Quality%20Code”)) if (inherits(result, "try-error")) message("year 2015 doesn't have data") else { ... do the usual stuff ... } On 18/09/2023 12:54 p.m., Nick Wray wrote: Hello I am downloading flow data from the UK national river flow archive (NRFA). I have code which works (thanks to previous help on r-help) but the problem is that before I make a call for the data for that particular year I don’t know whether the data exists for that particular year and catchment This is a typical url and it works if you paste it into the top line on a web page. 15007 is the code for the Pitnacree catchment in Scotland https://timeseries.sepa.org.uk/KiWIS/KiWIS?service=kisters=queryServices=0=getTimeseriesValues_path=1/15007/Q/15m.Cmd=2015-01-01=2015-01-31=Timestamp,Value,Quality%20Code It works in R as well with page<-read_html(" https://timeseries.sepa.org.uk/KiWIS/KiWIS?service=kisters=queryServices=0=getTimeseriesValues_path=1/15007/Q/15m.Cmd=2015-01-01=2015-01-31=Timestamp,Value,Quality%20Code ") yiq<-page |> html_element("table") |> html_table(header = TRUE) |> (\(x) { hdr <- unlist(x[3, ]) y <- x[-(1:3), ] names(y) <- hdr y })() print(nrow(yiq)) yiq But if I try to move onto another catchment Kenmore 15006 eg https://timeseries.sepa.org.uk/KiWIS/KiWIS?service=kisters=queryServices=0=getTimeseriesValues_path=1/15016/Q/15m.Cmd=2015-01-01=2015-01-31=Timestamp,Value,Quality%20Code So in R read_html(“ https://timeseries.sepa.org.uk/KiWIS/KiWIS?service=kisters=queryServices=0=getTimeseriesValues_path=1/15016/Q/15m.Cmd=2015-01-01=2015-01-31=Timestamp,Value,Quality%20Code ”) This doesn’t work because there’s no data for this catchment for this year I am pasting in different years (from say 1961 to 2017) in a loop (and this works if the data sets exist) but the problem is that if the data is not there (and there doesn’t seem to be a way of determining this elsewhere) and so there’s nothing to read, an error message comes up and halts the program loop, so that manually I have to reset the url to try to find out whether there is data for the next year. What I’d like to know is whether there’s any way in R of seeing whether the data set exists, and if doesn’t, moving on the next possibility without halting… Any thoughts appreciated Thanks Nick Wray [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merge and replace data
On 05/09/2023 4:55 a.m., roslinazairimah zakaria wrote: Hi all, I have these data x1 <- c(116,0,115,137,127,0,0) x2 <- c(0,159,0,0,0,159,127) I want : xx <- c(116,115,137,127,159, 127) I would like to merge these data into one column. Whenever the data is '0' it will be replaced by the value in the column which is non zero.. I tried append and merge but fail to get what I want. Others have pointed out pmax(x1, x2). For the sample data, even x1+x2 would give the same answer. The real question is what you want to do if both x1 and x2 have non-zero entries, or negative entries: pmax(x1, x2) will pick the larger one. It might be zero if the other is negative, and that doesn't match your description. x1+x2 will just give the sum, which doesn't match your description if both are non-zero. But maybe you want the x1 value unless it is zero, even if it is smaller than the x2 value: then you would use ifelse(x1 != 0, x1, x2) Similarly ifelse(x2 != 0, x2, x1) would prefer the x2 value. You should think about what you would do in these other cases as well. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Pkg-Collaboratos] BioShapes Almost-Package
On 03/09/2023 10:47 p.m., Jeff Newmiller wrote: Leonard... the reason roxygen exists is to allow markup in source files to be used to automatically generate the numerous files required by standard R packages as documented in Writing R Extensions. If your goal is to not use source files this way then the solution is to not use roxygen at all. Just create those files yourself by directly editing them from scratch. Just a bit of elaboration on Jeff's suggestion -- here's the workflow I prefer to using Roxygen. Once you have a function that works: 1. install the package 2. set your working directory to the package "man" directory 3. run `prompt(functionname)` 4. edit `functionname.Rd` in the "man" directory, which will already be filled in as a skeleton help file, with comments describing what else to add. Don't run prompt() again after editing, or you'll lose all your edits. But this is a good way to get started. I think for the first few times the comments are really helpful, but I wouldn't mind a way to suppress them. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems with installing R packages from source and running C++ in R, even on fresh R installation
On 30/08/2023 2:59 p.m., Ivan Krylov wrote: On Wed, 30 Aug 2023 16:31:20 + Christophe Bousquet wrote: So, yes, it seems possible for R to localize paths related to Rtools... But then, I really do not get where things go wrong... When installing packages containing code to compile, R eventually calls R CMD SHLIB. Same thing happens with inline C++: it gets stored in a temporary file, compiled into a *.dll using R CMD SHLIB and then loaded using dyn.load(). Write the following into a file named hello.c: #include #include SEXP hello(void) { SEXP ret = PROTECT(allocVector(STRSXP, 1)); SET_STRING_ELT(ret, 0, mkChar("hello")); UNPROTECT(1); return ret; } From within R, setwd() to the directory containing hello.c and run: tools::Rcmd('SHLIB -n hello.c') tools::Rcmd('SHLIB hello.c') What do the commands print? Does the second command fail? (Let's Cc: R-help@r-project.org in case people with more experience debugging Windows problems have a better idea what's going on.) It sounds exactly as though Rtools files aren't on the path that's in effect when R starts. That's probably the one stored in the registry. In the old days it was set in the System app in the Windows Control Panel under "Edit the system environment variables". I don't know if that's still true. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error "STRING_ELT() can only be applied to a 'character vector', not a 'list'" from rmarkdown
On 24/08/2023 1:58 p.m., Chris Evans via R-help wrote: I have an Rmarkdown file which is part of my distill "Rblog" (https://www.psyctc.org/Rblog/). It was knitting fine until last week, now knitting terminates with this: Rscript -e 'rmarkdown::render("creating-a-shiny-server.Rmd")' processing file: creating-a-shiny-server.Rmd output file: creating-a-shiny-server.knit.md /usr/bin/pandoc +RTS -K512m -RTS creating-a-shiny-server.knit.md --to html5 --from markdown+autolink_bare_uris+tex_math_single_backslash --output creating-a-shiny-server.html --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua --wrap preserve --standalone --table-of-contents --toc-depth 4 --variable toc-float=1 --highlight-style /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/arrow.theme --template /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/default.html '--metadata=link-citations:true' --include-in-header /tmp/Rtmp7WHAIE/fileb39b179ffd801html --include-in-header /tmp/Rtmp7WHAIE/fileb39b15b1e3532html --include-in-header /tmp/Rtmp7WHAIE/fileb39b13239652chtml --include-in-header /tmp/Rtmp7WHAIE/fileb39b1581627e8html --include-in-header /tmp/Rtmp7WHAIE/fileb39b12850a405html --include-before-body /tmp/Rtmp7WHAIE/fileb39b16f8d72a6html --include-before-body /tmp/Rtmp7WHAIE/fileb39b16ce17d77html --include-before-body /tmp/Rtmp7WHAIE/fileb39b12f851f86html --include-after-body /tmp/Rtmp7WHAIE/fileb39b14447b7b1html --include-after-body /tmp/Rtmp7WHAIE/fileb39b143ff6632html --include-after-body /tmp/Rtmp7WHAIE/fileb39b1345b1dddhtml --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /tmp/Rtmp7WHAIE/rmarkdown-strb39b160f391de.html --include-in-header /tmp/Rtmp7WHAIE/fileb39b164361476html Error in `xml_text<-.xml_node`(`*tmp*`, value = text) : STRING_ELT() can only be applied to a 'character vector', not a 'list' Calls: ... write_feed_xml -> add_child -> -> xml_text<-.xml_node In addition: There were 20 warnings (use warnings() to see them) Execution halted That function `xml_text<-.xml_node` is in the xml2 package, which was updated in early July. Do you think the error has been happening since you updated your copy, or did something else trigger it? One way to debug this is as follows. With the file in the directory where the error occurs, start R (or RStudio, it shouldn't matter), and run debug(xml2:::`xml_text<-.xml_node`) rmarkdown::render("creating-a-shiny-server.Rmd") If you're lucky, the error will happen on the first call to that function, and you can trace into it to see what's so weird. If you're unlucky, it will happen after many calls. Then you'll probably have to use trace() to identify which call causes problems (increment and print a counter on each call), then break just before the bad call and try to see what went wrong. Duncan Murdoch It's the same if I do it in Rstudio or from the command line like that so I think I can safely say it's not an Rstudio issue. The same happens with other Rmd files in the distill _posts directory. The really weird aspects are: 1) the html _is_ created fine (but if running in Rstudio it doesn't transfer to showing you the html) 2) the error message is only there if I run the Rmd in that directory, i.e. the 2023-08-19-creating-a-shiny-server directory in _posts or in _posts above that, but I move it up againif I move it to higher or other directories it works fine: Rscript -e 'rmarkdown::render("creating-a-shiny-server.Rmd")' processing file: creating-a-shiny-server.Rmd output file: creating-a-shiny-server.knit.md /usr/bin/pandoc +RTS -K512m -RTS creating-a-shiny-server.knit.md --to html5 --from markdown+autolink_bare_uris+tex_math_single_backslash --output creating-a-shiny-server.html --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua --wrap preserve --standalone --table-of-contents --toc-depth 4 --variable toc-float=1 --highlight-style /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/arrow.theme --template /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/default.html '--metadata=link-citations:true' --include-in-header /tmp/RtmpGMqTCm/fileb43a436c6281fhtml --include-in-header /tmp/RtmpGMqTCm/fileb43a455b7e5bdhtml --include-in-header /tmp/RtmpGMqTCm/fileb43a461db1ea1html --include-in-header /tmp/RtmpGMqTCm/fileb43a474a6e703html --include-before-body /tmp/RtmpGMqTCm/fileb43a494bd34html --include-before-body /tmp/RtmpGMqTC
Re: [R] Error "STRING_ELT() can only be applied to a 'character vector', not a 'list'" from rmarkdown
Could you post a link to the source for that Rmd file? Duncan Murdoch On 24/08/2023 1:58 p.m., Chris Evans via R-help wrote: I have an Rmarkdown file which is part of my distill "Rblog" (https://www.psyctc.org/Rblog/). It was knitting fine until last week, now knitting terminates with this: Rscript -e 'rmarkdown::render("creating-a-shiny-server.Rmd")' processing file: creating-a-shiny-server.Rmd output file: creating-a-shiny-server.knit.md /usr/bin/pandoc +RTS -K512m -RTS creating-a-shiny-server.knit.md --to html5 --from markdown+autolink_bare_uris+tex_math_single_backslash --output creating-a-shiny-server.html --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua --wrap preserve --standalone --table-of-contents --toc-depth 4 --variable toc-float=1 --highlight-style /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/arrow.theme --template /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/default.html '--metadata=link-citations:true' --include-in-header /tmp/Rtmp7WHAIE/fileb39b179ffd801html --include-in-header /tmp/Rtmp7WHAIE/fileb39b15b1e3532html --include-in-header /tmp/Rtmp7WHAIE/fileb39b13239652chtml --include-in-header /tmp/Rtmp7WHAIE/fileb39b1581627e8html --include-in-header /tmp/Rtmp7WHAIE/fileb39b12850a405html --include-before-body /tmp/Rtmp7WHAIE/fileb39b16f8d72a6html --include-before-body /tmp/Rtmp7WHAIE/fileb39b16ce17d77html --include-before-body /tmp/Rtmp7WHAIE/fileb39b12f851f86html --include-after-body /tmp/Rtmp7WHAIE/fileb39b14447b7b1html --include-after-body /tmp/Rtmp7WHAIE/fileb39b143ff6632html --include-after-body /tmp/Rtmp7WHAIE/fileb39b1345b1dddhtml --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /tmp/Rtmp7WHAIE/rmarkdown-strb39b160f391de.html --include-in-header /tmp/Rtmp7WHAIE/fileb39b164361476html Error in `xml_text<-.xml_node`(`*tmp*`, value = text) : STRING_ELT() can only be applied to a 'character vector', not a 'list' Calls: ... write_feed_xml -> add_child -> -> xml_text<-.xml_node In addition: There were 20 warnings (use warnings() to see them) Execution halted It's the same if I do it in Rstudio or from the command line like that so I think I can safely say it's not an Rstudio issue. The same happens with other Rmd files in the distill _posts directory. The really weird aspects are: 1) the html _is_ created fine (but if running in Rstudio it doesn't transfer to showing you the html) 2) the error message is only there if I run the Rmd in that directory, i.e. the 2023-08-19-creating-a-shiny-server directory in _posts or in _posts above that, but I move it up againif I move it to higher or other directories it works fine: Rscript -e 'rmarkdown::render("creating-a-shiny-server.Rmd")' processing file: creating-a-shiny-server.Rmd output file: creating-a-shiny-server.knit.md /usr/bin/pandoc +RTS -K512m -RTS creating-a-shiny-server.knit.md --to html5 --from markdown+autolink_bare_uris+tex_math_single_backslash --output creating-a-shiny-server.html --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua --wrap preserve --standalone --table-of-contents --toc-depth 4 --variable toc-float=1 --highlight-style /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/arrow.theme --template /home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/default.html '--metadata=link-citations:true' --include-in-header /tmp/RtmpGMqTCm/fileb43a436c6281fhtml --include-in-header /tmp/RtmpGMqTCm/fileb43a455b7e5bdhtml --include-in-header /tmp/RtmpGMqTCm/fileb43a461db1ea1html --include-in-header /tmp/RtmpGMqTCm/fileb43a474a6e703html --include-before-body /tmp/RtmpGMqTCm/fileb43a494bd34html --include-before-body /tmp/RtmpGMqTCm/fileb43a42fbfec67html --include-before-body /tmp/RtmpGMqTCm/fileb43a4273d84ebhtml --include-after-body /tmp/RtmpGMqTCm/fileb43a4725e33cahtml --include-after-body /tmp/RtmpGMqTCm/fileb43a43d386888html --include-after-body /tmp/RtmpGMqTCm/fileb43a43f19b459html --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /tmp/RtmpGMqTCm/rmarkdown-strb43a43033daa0.html --include-in-header /tmp/RtmpGMqTCm/fileb43a42807e405html Output created: creating-a-shiny-server.html Warning message: In as.character.POSIXt(as.POSIXlt(x), ...) : as.character(td, ..) no longer obeys a 'format' argument; use format(td, ..) ? The 20 warnings are: > warnings() Warning messages: 1: In as.character.POSIXt(as.POSIXlt(x),
Re: [R] col2rgb() function
On 23/07/2023 2:15 p.m., Nick Wray wrote: Hello I have a palette vector of colour blind colours (in hexadecimal) which I’m using for plots, but they are not see-through, and as I wanted to overlay some histograms I wanted to convert these colours to rgb, when you can set the opacity. I have found the function col2rgb(), which works in the sense that it gives a vector of numbers but these don’t work directly in rgb because they are too big. If I divide through to make them all less than 1 I don’t get the corresponding colour-blind hue, but something somewhat off. Here is the colour-blind palette in a plot: *cb8<- c("#00", "#E69F00", "#56B4E9", "#009E73","#F0E442", "#0072B2", "#D55E00", "#CC79A7")* *plot(0,0,xlim=c(1,8),ylim=c(0,1))* *points(1:8,rep(0.5,8),col=cb8,pch=19,cex=2)* so if I try to convert the red dot ("#D55E00") (number 7) I get *col2rgb("#D55E00"* [,1] red213 green 94 blue 0 *points(7,0.25,col=rgb(rgb(213,94,0)),pch=19,cex=2)* gives me an error message and although if I divide through *points(7,0.25,col=rgb(213/307,94/307,0),pch=19,cex=2)* gives me a reddish dot, but not the same as in the colour-blind palette Why are you dividing by 307? You should divide by 255. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Line Directives in Sweave Document
On 28/06/2023 1:39 a.m., Iris Simmons wrote: 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 do not appear: { + fun <- function() { + pkg::fun() + } + + + fun() + } I tried faking a line directive by writing it twice: <>= { #line 1 "file1.R" #line 1 "file1.R" fun <- function() { pkg::fun() } #line 1 "file2.R" #line 1 "file2.R" fun() } @ but then the rendered fake line directive looks bad because it's out by one space so if it is copy-pasted, it wouldn't actually function as shown. So is there an option I can set to have the line directives displayed, or something else I can change to get it working? Thank you! Maybe if you put a zero-width space before the fake version, instead of a regular space? That's \u200B in Unicode; there are various other encodings of it. Put it after the # so that it isn't a syntax error, i.e. #\u200Bline 1 "file1.R" or if that shows the escape, print that string and copy the actual character into your document. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] warnng to an error....
On 17/06/2023 1:16 p.m., akshay kulkarni wrote: Dear members, I have the following code: FUN(OHLCDataEP[[63]]) Error in (class(x) == "xts") || (class(x) == "zoo") : 'length = 2' in coercion to 'logical(1)' traceback() 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]]) class(OHLCDataEP[[63]]) [1] "xts" "zoo" The following is in ygix() : if((class(x) == "xts") || (class(x) == "zoo") I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. What should I do? Change it to: if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same. The vector of classes in the second argument is read as "any of these classes". Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Why install.packages(repos = X) does not override the 'repos' R option?
(Sorry, forgot "Reply all" last time.) That's an RStudio bug. It doesn't happen if you use install.packages() from R. Duncan Murdoch On 14/06/2023 9:22 a.m., Dean Attali wrote: There is a default R option for which repos to install from - `getOption("repos")`. When installing a package using install.packages(), you can provide a `repos` parameter. The default value of that parameter is `getOption("repos")`. I assumed that this parameter would override the R option. In other words, I assumed that if the parameter is provided, then the R option would not even be looked at. But after testing this, it seems this is not the case. For example, running the following two lines in an R session: options(repos=c(CRAN="https://BADNAME.com;)) install.packages("vctrs", repos = "https://cloud.R-project.org;) I would have expected the first line to be rendered meaningless, but in fact after running the second line I see errors about the BADNAME repository. This feels like a bug to me, but I'm sure there's a reason behind this. Does anyone know why this is the case? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting directly to memory?
Is there a way to open a graphics device that plots entirely to an array or raster in memory? I'd prefer it to use base graphics, but grid would be fine if it makes a difference. For an explicit example, I'd like to do the equivalent of this: filename <- tempfile(fileext = ".png") png(filename) plot(1:10, 1:10) dev.off() library(png) img <- readPNG(filename) unlink(filename) which puts the desired plot into the array `img`, but I'd like to do it without needing the `png` package or the temporary file. A possibly slightly simpler request would be to do this only for plotting text, i.e. I'd like to rasterize some text into an array. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] environments: functions within functions
I agree with Iris: the switch() solution looks like the best option here. The only change I'd make is to pass the dots down to the print function (or possibly warn about using them if those functions don't support any other parameters). Duncan Murdoch On 25/05/2023 8:20 p.m., Iris Simmons wrote: 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, gamma = printgamma (x, digits), lnorm = printlnorm (x, digits), normal = printnormal (x, digits), weibull = printweibull(x, digits), stop(gettextf("invalid '%s' value", "x$family", domain = "R"))) invisible(x) } environment(print.mixfitEM) <- getNamespace("mixR") print.mixfitEM <- compiler::cmpfun(print.mixfitEM) ``` This is nice because 'x' is no longer evaluated twice (you could try this yourself with something like `mixR:::print.mixfitEM(writeLines("testing"))`, you'll see the output twice, once for `x$family` and a second for evaluating `match.call()` expression), it follows standard evaluation, and 'x' is returned invisibly at the end, like most other `print` methods. If you really wanted to continue using `eval`, you could instead do something like ```R print.mixfitEM <- function (x, digits = getOption("digits"), ...) { expr <- quote(printfunction(x, digits)) expr[[1L]] <- as.symbol(paste0("print", x$family)) eval(expr) invisible(x) } environment(print.mixfitEM) <- getNamespace("mixR") print.mixfitEM <- compiler::cmpfun(print.mixfitEM) ``` This also solves the same issues, but it's ugly and slower. At least for now, I would copy one of the functions above into the site-wide startup profile file or your user profile, along with ```R utils::assignInNamespace("print.mixfitEM", print.mixfitEM, "mixR") ``` This does have the unfortunate side effect of loading **mixR** every time an R session is launched, but you could also put it inside another function like: ```R fix.mixR.print.mixfitEM <- function () { print.mixfitEM <- function(x, digits = getOption("digits"), ...) { switch(x$family, gamma = printgamma (x, digits), lnorm = printlnorm (x, digits), normal = printnormal (x, digits), weibull = printweibull(x, digits), stop(gettextf("invalid '%s' value", "x$family", domain = "R"))) invisible(x) } environment(print.mixfitEM) <- getNamespace("mixR") print.mixfitEM <- compiler::cmpfun(print.mixfitEM) utils::assignInNamespace("print.mixfitEM", print.mixfitEM, "mixR") } ``` which you would then call in your scripts before using **mixR**. I hope this helps! On Thu, May 25, 2023 at 10:19 AM Sarah Goslee wrote: Hi, I ran into a problem with S3 method dispatch and scoping while trying to use functions from the mixR package within my own functions. I know enough to find the problem (I think!), but not enough to fix it myself. The problem isn't really a package-specific problem, so I'm starting here, and will file an issue with the maintainer once I have a solution. Detailed explanation below, but briefly, the S3 methods in this package use match.call() and then eval() to select the correct internal method. This works fine from the command line, but if the method is called from within another function, the use of environment() within eval() means that the objects passed to the wrapper function are no longer visible within the eval() call. I have a two-part question: A. How do I get around this right now? B. What would the correct approach be for the package authors? library(mixR) # first example from ?mixfit ## fitting the normal mixture models set.seed(103) x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 1)) data <- bin(x, seq(-1, 8, 0.25)) fit1 <- mixfit(x, ncomp = 2) # raw data rm(x, data) ### # simple function funworks <- function(x) { print(x) } ### # almost identical simple function funfails <- function(thisx) { print(thisx) } ### funworks(fit1) funfails(fit1) ### The explanation as I understand it... print called on this object gets passed to print.mixfitEM(), which is: function (x, digits = getOption("digits"), ...) { family <- x$family mc <- match.call() mc$digits <- digits fun.name <- paste0("print", family) mc[[1]] <- as.name(fun.name) eval(mc, environment()) } Working through the calls, when eval() is called from within funfails(), mc is printnormal(x = thisx, digits = 7) and the calling environment does not contain thisx. In f
Re: [R] environments: functions within functions
On 25/05/2023 10:18 a.m., Sarah Goslee wrote: Hi, I ran into a problem with S3 method dispatch and scoping while trying to use functions from the mixR package within my own functions. I know enough to find the problem (I think!), but not enough to fix it myself. The problem isn't really a package-specific problem, so I'm starting here, and will file an issue with the maintainer once I have a solution. Detailed explanation below, but briefly, the S3 methods in this package use match.call() and then eval() to select the correct internal method. This works fine from the command line, but if the method is called from within another function, the use of environment() within eval() means that the objects passed to the wrapper function are no longer visible within the eval() call. I have a two-part question: A. How do I get around this right now? B. What would the correct approach be for the package authors? I'll try B first. The problem is that they want to look up fun.name in the environment that is visible from print.mixfitEM(), i.e. the mixR internal namespace environment, and they also want to evaluate that function the way it was evaluated when print.mixfitEM was called, i.e. in parent.frame(). R doesn't support that kind of thing in one step, so they should do it in two steps, e.g. rewriting print.mixfitEM something like this: function (x, digits = getOption("digits"), ...) { family <- x$family mc <- match.call() mc$digits <- digits fun.name <- paste0("print", family) e <- new.env(parent = parent.frame()) e[[fun.name]] <- get(fun.name) mc[[1]] <- as.name(fun.name) eval(mc, e) } This tries to get the function ("printnormal") from the local evaluation environment, but there's nothing there named "printnormal", so it goes to the parent environment, and gets it there. It puts it in a new environment whose parent is parent.frame() and everything works. For part A of your question, I can't think of any workaround other than using x as the name of the variable that is passed to print(). You could hide that fact by making a local function to do it, e.g. myprint <- function(x) print(x) and then calling myprint(fit1). Duncan Murdoch library(mixR) # first example from ?mixfit ## fitting the normal mixture models set.seed(103) x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 1)) data <- bin(x, seq(-1, 8, 0.25)) fit1 <- mixfit(x, ncomp = 2) # raw data rm(x, data) ### # simple function funworks <- function(x) { print(x) } ### # almost identical simple function funfails <- function(thisx) { print(thisx) } ### funworks(fit1) funfails(fit1) ### The explanation as I understand it... print called on this object gets passed to print.mixfitEM(), which is: function (x, digits = getOption("digits"), ...) { family <- x$family mc <- match.call() mc$digits <- digits fun.name <- paste0("print", family) mc[[1]] <- as.name(fun.name) eval(mc, environment()) } Working through the calls, when eval() is called from within funfails(), mc is printnormal(x = thisx, digits = 7) and the calling environment does not contain thisx. In funworks(), it's printnormal(x = x, digits = 7) and x is found. So, I can get around the problem by naming my argument x, as in funworks(), but that's unsatisfying. Is there something else I can do to get my functions to work? And what's the correct way to do what print.mixfitEM() is doing, so that it works regardless? I poked around for a while, but didn't find a clear (to me!) answer. Thanks, Sarah __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl not plotting properly
On 05/05/2023 7:41 a.m., Jiayue Wang wrote: 在 5/5/23 19:15, Duncan Murdoch 写道: On 05/05/2023 6:48 a.m., Jiayue Wang wrote: Thanks Duncan. glxgears works at the terminal; tcltk::tktoplevel() outputs the following: $ID [1] ".1" $env attr(,"class") [1] "tkwin" Jiayue But no window opens for tcltk::tktoplevel()? Sounds like R isn't seeing your DISPLAY variable. Does Sys.getenv("DISPLAY") show the same thing in R as you see when printing that environment variable (using e.g. `echo $DISPLAY`) in the terminal? Oh yes, a window did open for tcltk::tktoplevel(), I forgot to mention it, sorry. With Sys.getenv("DISPLAY"), I got [1] ":0" In that case, it sounds like it's purely an rgl issue, but I don't really have anything else to suggest about how to fix it. There is a workaround: Run the `rglwidget()` function whenever you want to see a plot, and it should open in your browser. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl not plotting properly
On 05/05/2023 6:48 a.m., Jiayue Wang wrote: Thanks Duncan. glxgears works at the terminal; tcltk::tktoplevel() outputs the following: $ID [1] ".1" $env attr(,"class") [1] "tkwin" Jiayue But no window opens for tcltk::tktoplevel()? Sounds like R isn't seeing your DISPLAY variable. Does Sys.getenv("DISPLAY") show the same thing in R as you see when printing that environment variable (using e.g. `echo $DISPLAY`) in the terminal? Duncan Murdoch 在 5/5/23 16:45, Duncan Murdoch 写道: On 05/05/2023 2:24 a.m., Jiayue Wang wrote: Hi I can't get rgl working. I installed rgl, loaded it, but it seems all plot3d codes have failed: remotes::install_github("dmurdoch/rgl") library(rgl) open3d() x <- sort(rnorm(1000)) y <- rnorm(1000) z <- rnorm(1000) + atan2(x, y) plot3d(x, y, z, col = rainbow(1000)) I see no plotting at all. Am I missing some important system library or whatever? I'm using Linux Mint 23. Thanks! If you install the version from CRAN, do you get the same results? rgl needs X11 on your system. Do other programs using it work, e.g. try running "glxgears" at the terminal, and try running "tcltk::tktoplevel()" in R. BTW, this list isn't for contributed package support, so if it turns out that only rgl is failing, it may be best to move the discussion to https://github.com/dmurdoch/rgl/issues . Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl not plotting properly
On 05/05/2023 2:24 a.m., Jiayue Wang wrote: Hi I can't get rgl working. I installed rgl, loaded it, but it seems all plot3d codes have failed: remotes::install_github("dmurdoch/rgl") library(rgl) open3d() x <- sort(rnorm(1000)) y <- rnorm(1000) z <- rnorm(1000) + atan2(x, y) plot3d(x, y, z, col = rainbow(1000)) I see no plotting at all. Am I missing some important system library or whatever? I'm using Linux Mint 23. Thanks! If you install the version from CRAN, do you get the same results? rgl needs X11 on your system. Do other programs using it work, e.g. try running "glxgears" at the terminal, and try running "tcltk::tktoplevel()" in R. BTW, this list isn't for contributed package support, so if it turns out that only rgl is failing, it may be best to move the discussion to https://github.com/dmurdoch/rgl/issues . Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question about update()
On 04/05/2023 4:34 a.m., Adelchi Azzalini wrote: On 4 May 2023, at 10:26, Duncan Murdoch wrote: On 04/05/2023 4:05 a.m., Adelchi Azzalini via R-help wrote: Hi. There must be something about the use of update() which I do not grasp, as the next exercise indicates. Suppose that obj is an object returned by a call to lm() or glm(). Next, a new variable xf is constructed using the same dataframe used for producing obj. Then obj$data <- cbind(obj$data, xf=xf) new.obj <- update(obj, . ~ . + xf) generates Error in eval(predvars, data, env) : object 'xf' not found Could somebody explain what I got wrong, and how to fix it? I don't think you should be modifying the obj$data element: as far as I can see, it's not used during the update, which will just re-evaluate the original call to glm(). So you should modify the dataframe that you passed in when creating obj. Thanks, Duncan. What you indicate is surely the ideal route. Unfortunately, in my case this is not feasible, because the construction of xf and the update call are within an iterative procedure where xf is changed at each iteration, so that the steps obj$data <- cbind(obj$data, xf=xf) new.obj <- update(obj, . ~ . + xf) must be repeated hundreds of times, each with a different xf. Sorry, that doesn't make sense. You didn't show us complete code, but presumably it's preceded by something like this: obj <- glm( ..., data = somedata) So change your modification to this: somedata$xf <- xf That can be done hundreds of times. This will need to be more elaborate if the function doing the iteration has a copy of obj but doesn't have a copy of somedata, but there are lots of ways to resolve that. Without seeing complete code, I can't recommend which one to use. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grDevices::hcl.colors using two colours: Bug or Feature?
On 28/04/2023 6:18 a.m., Achim Zeileis wrote: On Fri, 28 Apr 2023, Achim Zeileis wrote: This was introduced in 4.3.0 (hence Rui cannot reproduce it in 4.2.3). It's a bug and was introduced when fixing this other bug: https://bugs.R-project.org/show_bug.cgi?id=18476 https://hypatia.math.ethz.ch/pipermail/r-help/2023-February/476960.html Apparently, it only affects the case with n = 2 for diverging and divergingx palettes. The culprit is this line: i <- if(n2 == 1L) 0 else seq.int(1, by = -2/(n - 1), length.out = n2) I think n2 == 1L is not the right condition and we need to distinguish n = 1 and n = 2. I think the solution is simply to use n == 1L instead of n2 == 1L, both in "diverging" (line 188 in hcl.colors.R) and "divergingx" (line 197). Duncan, maybe you can have a look at this as well? I agree that the two changes solve this problem. I couldn't spot any other places that would need fixing. Duncan Murdoch Will have a closer look... Thanks for reporting this! Achim On Fri, 28 Apr 2023, Rui Barradas wrote: Às 06:01 de 28/04/2023, Stevie Pederson escreveu: Hi, I'm not sure if this is a bug or a feature, but after updating to Rv4.3, if requesting two colours from hcl.colors() you now get the same colour twice. This occurs for all palettes I've tried. My reprex: hcl.colors(2, "Vik") [1] "#F1F1F1" "#F1F1F1" As I have multiple workflows I run repeatedly with A vs B comparisons, this has just broken the visualisations in many of them. Obviously a workaround is hcl.colors(3, "Vik")[c(1, 3)] but this seems rather unintuitive. Thanks in advance, Stevie sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.6 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0 locale: [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_AU.UTF-8LC_COLLATE=en_AU.UTF-8 [5] LC_MONETARY=en_AU.UTF-8LC_MESSAGES=en_AU.UTF-8 [7] LC_PAPER=en_AU.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C time zone: Australia/Adelaide tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_4.3.0 tools_4.3.0 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Hello, I cannot reproduce this on Windows. hcl.colors(2, "Vik") # [1] "#002E60" "#3E2000" clrs <- sapply(hcl.pals(), \(p) hcl.colors(2, p)) any(apply(clrs, 2, \(x) x[1] == x[2])) # [1] FALSE sessionInfo() # R version 4.2.3 (2023-03-15 ucrt) # Platform: x86_64-w64-mingw32/x64 (64-bit) # Running under: Windows 10 x64 (build 22621) # # Matrix products: default # # locale: # [1] LC_COLLATE=Portuguese_Portugal.utf8 LC_CTYPE=Portuguese_Portugal.utf8 # [3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C # [5] LC_TIME=Portuguese_Portugal.utf8 # # attached base packages: # [1] stats graphics grDevices utils datasets methods base # # loaded via a namespace (and not attached): # [1] compiler_4.2.3 Hope this helps, Rui Barradas __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grDevices::hcl.colors using two colours: Bug or Feature?
This is a 4.3.0 reversion. I'm seeing it as well on R version 4.3.0 RC (2023-04-13 r84266) Platform: x86_64-apple-darwin20 (64-bit) Running under: macOS Monterey 12.6.5 Duncan Murdoch On 28/04/2023 5:51 a.m., Rui Barradas wrote: Às 06:01 de 28/04/2023, Stevie Pederson escreveu: Hi, I'm not sure if this is a bug or a feature, but after updating to Rv4.3, if requesting two colours from hcl.colors() you now get the same colour twice. This occurs for all palettes I've tried. My reprex: hcl.colors(2, "Vik") [1] "#F1F1F1" "#F1F1F1" As I have multiple workflows I run repeatedly with A vs B comparisons, this has just broken the visualisations in many of them. Obviously a workaround is hcl.colors(3, "Vik")[c(1, 3)] but this seems rather unintuitive. Thanks in advance, Stevie sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.6 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0 locale: [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_AU.UTF-8LC_COLLATE=en_AU.UTF-8 [5] LC_MONETARY=en_AU.UTF-8LC_MESSAGES=en_AU.UTF-8 [7] LC_PAPER=en_AU.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C time zone: Australia/Adelaide tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_4.3.0 tools_4.3.0 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Hello, I cannot reproduce this on Windows. hcl.colors(2, "Vik") # [1] "#002E60" "#3E2000" clrs <- sapply(hcl.pals(), \(p) hcl.colors(2, p)) any(apply(clrs, 2, \(x) x[1] == x[2])) # [1] FALSE sessionInfo() # R version 4.2.3 (2023-03-15 ucrt) # Platform: x86_64-w64-mingw32/x64 (64-bit) # Running under: Windows 10 x64 (build 22621) # # Matrix products: default # # locale: # [1] LC_COLLATE=Portuguese_Portugal.utf8 LC_CTYPE=Portuguese_Portugal.utf8 # [3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C # [5] LC_TIME=Portuguese_Portugal.utf8 # # attached base packages: # [1] stats graphics grDevices utils datasets methods base # # loaded via a namespace (and not attached): # [1] compiler_4.2.3 Hope this helps, Rui Barradas __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot R graphs in aws
On 20/04/2023 7:43 a.m., Naresh Gurbuxani wrote: In my Amazon Web Services (AWS) account, I use R via emacs launched from terminal. While R computations work well, viewing graphs is inconvenient. I am not able to use screen device. I can send graphs to a png or pdf file, then open the file. I would like a setup where code is run in one window while graphs are displayed in another window. Has anyone created a setup like this? You don't say which OS's you are running, but if you can run an X server on your local machine, the remote R process should be able to display graphs there (as long as it is running on a Unix-alike). Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Package Caret
You should post the result of running sessionInfo(), and tell us how you installed R. Your installation seems very broken. Duncan Murdoch On 14/04/2023 3:45 a.m., Gábor Malomsoki wrote: This is the error then: error in prettyseq(1:ncol(out)) : could not find function "prettyseq" Eric Berger schrieb am Fr., 14. Apr. 2023, 09:06: What happens if you do the following? library(caret) ?caret::createDataPartition i.e. to confirm that caret is loaded, seek help on this function On Fri, Apr 14, 2023 at 9:56 AM Gábor Malomsoki wrote: Eric, Yes, i know, i am calling the package, but this is not working. I saw a similar question in Stackoverflow, advising install package Rcpp, but this one i am unable to install. Eric Berger schrieb am Fr., 14. Apr. 2023, 08:47: You first have to load the package using the library command. library(caret) Then you can call createDataPartition. e.g. data(oil) createDataPartition(oilType,2) HTH, Eric On Fri, Apr 14, 2023 at 7:52 AM Gábor Malomsoki < gmalomsoki1...@gmail.com> wrote: Dear all, When i try to use createDataPartition after calling package 'caret', i get the message: "could not find function createDataPartition" I use: R-4.2.3 for Windows RStudio-2023.03.0-386 Do you have any experience with this failure? Thank you! Best regards Gabor [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] aborting the execution of a script...
This is what I get: > source("~/temp/test.R", echo = TRUE) > print(1) [1] 1 > stop("here") Error in eval(ei, envir) : here I get similar output in every variation I tried. It never prints the 2. On 12/04/2023 8:13 a.m., akshay kulkarni wrote: Dear Duncan, What if I use source() with echo? I am using that in RStudio. THanking you, Yours sincerely AKSHAY M KULKARNI -------- *From:* Duncan Murdoch *Sent:* Wednesday, April 12, 2023 5:35 PM *To:* akshay kulkarni ; R help Mailing list *Subject:* Re: [R] aborting the execution of a script... On 12/04/2023 7:03 a.m., akshay kulkarni wrote: Dear members, I have a script which I source it interactively. I have the following questions: 1. If there is an error in an expression, an error message is printed, but the execution continues till the end of the script. I am sourcing with echo. Is there any way to abort the execution when the first error occurs? This happens with R CMD BATCH. If there is an error midway, an error message is printed in the output file and the execution aborts. Is there a way to mimic this with source()? 2. I am trying to abort the execution with ESC key, but again the same thing happens: it aborts the current expression but continues on. How to abort an R script with source()? I am using RStudio in windows. I don't see this behaviour. If I put this in a script: print(1) stop("here") print(2) then execution stops at the "stop" line if I use source(), or R CMD BATCH , or in RStudio, Run or Source gives the same behaviour. I think older versions of RStudio would have run all three lines using Run, but all the other methods have stopped at the stop() line. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] aborting the execution of a script...
On 12/04/2023 7:03 a.m., akshay kulkarni wrote: Dear members, I have a script which I source it interactively. I have the following questions: 1. If there is an error in an expression, an error message is printed, but the execution continues till the end of the script. I am sourcing with echo. Is there any way to abort the execution when the first error occurs? This happens with R CMD BATCH. If there is an error midway, an error message is printed in the output file and the execution aborts. Is there a way to mimic this with source()? 2. I am trying to abort the execution with ESC key, but again the same thing happens: it aborts the current expression but continues on. How to abort an R script with source()? I am using RStudio in windows. I don't see this behaviour. If I put this in a script: print(1) stop("here") print(2) then execution stops at the "stop" line if I use source(), or R CMD BATCH , or in RStudio, Run or Source gives the same behaviour. I think older versions of RStudio would have run all three lines using Run, but all the other methods have stopped at the stop() line. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R does not run under latest RStudio
On 06/04/2023 6:49 a.m., Steven Yen wrote: The RStudio list generally does not respond to free version users. I was hoping someone one this (R) list would be kind enough to help me. The quality of RStudio has gone way downhill lately. Although Posit is now a big company, I think there are only 1 or 2 people there who really know what's going on in the RStudio IDE, and they are busy on other things these days. So my advice to you would be to switch to the Windows rgui front end (which comes with R, so questions about it will be addressed here), or switch to a different OS, or just stay with the old RStudio version that was working for you. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] on lexical scoping....
It seems mostly correct. Here are a few quibbles: - I don't think "owner" is a good description of the parent environment. Usually when I use owner in computing, there's an implication that the owner controls what it owns, is responsible for allocating and destroying it, etc. Parent environments are targets of a pointer from other environments that list them as their "enclosure", but they have no record of their children. - The analogy that all roads lead to the search list is wrong. There's no reason you couldn't create an environment whose parent was the empty environment. But with the qualifier "when we start in R_GlobalEnv" it's correct, so this complaint is just about the wording. - The description of what Imports does is wrong. What is described there is what the `import()` directive in NAMESPACE does. The Imports line in DESCRIPTION just guarantees that the named package is loaded, it doesn't import anything. And the `importFrom()` directive in NAMESPACE isn't discussed. - It gets bad near the end in the "Curveball" section. I'd just skip that. It's not at all true that all functions in a package have the package's namespace environment as their environment. There are lots of real examples where that's not true. Functions that maintain persistent records (e.g. the base function conflictRules()) often have a private environment, and occasionally packages import functions from other packages by simple assignment, so they end up in the namespace environment of the importer but still have the namespace environment of the exporter associated with them. And the last diagram (the revised one with all solid lines) is just misleading. Duncan On 04/04/2023 7:53 p.m., Mark Leeds wrote: obviously, everyone has different opinions on what's useful but I always found this document quite helpful. I think, in the past, someone said that there are some incorrect statements in but I'm not sure what they are. https://askming.github.io/study_notes/Stats_Comp/Note-How%20R%20searches%20and%20finds%20stuff.html On Tue, Apr 4, 2023 at 7:06 PM Bert Gunter wrote: The following *might* be of use to you. If you can predict what the various function invocations will do, I think you have a reasonable grasp of how lexical scoping works in R (contrary or supplementary opinions welcome). It is the sort of thing you will find in the references also. If this is all obvious, sorry for wasting your time. ### search() ls() dat <- list(x =2) attach(dat,2) search() f <- function(){ g <- function() x x <- 3 g} h <- f() g <- function()x ls() h() g() detach(dat) h() g() ## ## Here is what this gives starting with an empty .GlobalEnv. ## search() [1] ".GlobalEnv""package:tools" "package:lattice" "tools:rstudio" [5] "package:stats" "package:graphics" "package:grDevices" "package:utils" [9] "package:datasets" "package:methods" "Autoloads" "package:base" ls() character(0) dat <- list(x =2) attach(dat,2) search() [1] ".GlobalEnv""dat" "package:tools" "package:lattice" [5] "tools:rstudio" "package:stats" "package:graphics" "package:grDevices" [9] "package:utils" "package:datasets" "package:methods" "Autoloads" [13] "package:base" f <- function(){ +g <- function() x +x <- 3 +g} h <- f() g <- function()x ls() [1] "dat" "f" "g" "h" h() [1] 3 g() [1] 2 detach(dat) h() [1] 3 g() Error in g() : object 'x' not found -- Bert On Tue, Apr 4, 2023 at 6:56 AM akshay kulkarni wrote: Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. Why doesn't it look further in the environment stack, like that of packages? There are thousands of packages that contain the variable named x. Of course, that happens if the above code is in a function (or does it?). What concept of R is at work in this dichotomy? THanking you, Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __
Re: [R] on lexical scoping....
No, there are lots of situations where that doesn't make sense. You don't want to have to define local copies of the functions from every package you use, for example. I think the takeaway is to learn how R scoping works, and keep things simple. That's one reason I tend to avoid "tidyverse" packages. There are a lot of really good ideas in those packages, but "tidy evaluation" is far too complicated and hard to understand, and I think it confuses people, so they don't understand the really very simple R scoping rules. Duncan Murdoch On 04/04/2023 10:59 a.m., akshay kulkarni wrote: Dear Duncan, THanks for the reply...! So the takeaway is that define the symbol in the same environment before using it right!? Thanking you, Yours sincerely, AKSHAY M KULKARNI ---- *From:* Duncan Murdoch *Sent:* Tuesday, April 4, 2023 8:21 PM *To:* akshay kulkarni ; Deepayan Sarkar *Cc:* R help Mailing list *Subject:* Re: [R] on lexical scoping You can't change the basic way R searches, but you can ask for a different kind of search. For example, to see if "x" exists, you can use exists("x") and it will do the default search, but exists("x", inherits = FALSE) will only look in the current environment. The get() function has a similar argument which returns the value Unfortunately these functions have overly complicated argument lists because they are based on functions in S from 30-40 years ago, and it had very different scoping rules. My advice would be to ignore the "where" and "frame" arguments, and always use "envir" if you want to say where to look. Duncan Murdoch On 04/04/2023 10:28 a.m., akshay kulkarni wrote: Dear Deepayan, THanks for the pithy, pointed reply. But isn't it risky? Can I somehow get a warning when x is not defined in the global environment but takes on a value from one of the loaded packages? any packages for that? THanking you, Yours sincerely, AKSHAY M KULKARNI From: Deepayan Sarkar Sent: Tuesday, April 4, 2023 7:51 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] on lexical scoping On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni mailto:akshay...@hotmail.com>> wrote: Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. That is not the correct interpretation of the error. R will happily evaluate y <- pi*10 even if the global environment does not contain pi. The "environments" where R will look is given by search() If you manage to find a package that defines 'x' (and exports it), attaching it will put the package on the search path, and then your call will indeed no longer give an error. -Deepayan Why doesn't it look further in the environment stack, like that of packages? There are thousands of packages that contain the variable named x. Of course, that happens if the above code is in a function (or does it?). What concept of R is at work in this dichotomy? THanking you, Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]] __ R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] on lexical scoping....
You can't change the basic way R searches, but you can ask for a different kind of search. For example, to see if "x" exists, you can use exists("x") and it will do the default search, but exists("x", inherits = FALSE) will only look in the current environment. The get() function has a similar argument which returns the value Unfortunately these functions have overly complicated argument lists because they are based on functions in S from 30-40 years ago, and it had very different scoping rules. My advice would be to ignore the "where" and "frame" arguments, and always use "envir" if you want to say where to look. Duncan Murdoch On 04/04/2023 10:28 a.m., akshay kulkarni wrote: Dear Deepayan, THanks for the pithy, pointed reply. But isn't it risky? Can I somehow get a warning when x is not defined in the global environment but takes on a value from one of the loaded packages? any packages for that? THanking you, Yours sincerely, AKSHAY M KULKARNI From: Deepayan Sarkar Sent: Tuesday, April 4, 2023 7:51 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] on lexical scoping On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni mailto:akshay...@hotmail.com>> wrote: Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. That is not the correct interpretation of the error. R will happily evaluate y <- pi*10 even if the global environment does not contain pi. The "environments" where R will look is given by search() If you manage to find a package that defines 'x' (and exports it), attaching it will put the package on the search path, and then your call will indeed no longer give an error. -Deepayan Why doesn't it look further in the environment stack, like that of packages? There are thousands of packages that contain the variable named x. Of course, that happens if the above code is in a function (or does it?). What concept of R is at work in this dichotomy? THanking you, Yours sincerely, AKSHAY M KULKARNI [[alternative HTML version deleted]] __ R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] on lexical scoping....
On 04/04/2023 10:35 a.m., akshay kulkarni wrote: Dear Duncan, THanks for the reply. I am looking at the technical point. The behavior you just described, as far as I know, is only for functions right? No, not at all. Every function you write in R has an associated environment (which you can find using environment(fn)). That only applies to searches taking place while evaluating the function. The starting point is a temporary environment to hold local variables, called the "evaluation frame". The parent of that environment is the environment given by environment(fn). When you type something at the top level, evaluation is done very similarly, except that the starting point for the search is the global environment. THre is no documentation ever, which says that the code looks for x in the search path. Could you please point me to some resources where I can find further information on lexical scoping for the code "typed" in the console (but not in a function)? See section 3.5.1 in the R Language Definition for a description of the relation between the global environment and the search list. See section 2.1.10 in that manual for how R looks up variables. Duncan Murdoch THanking you, Yours sincerely, AKSHAY M KULKARNI ---- *From:* Duncan Murdoch *Sent:* Tuesday, April 4, 2023 7:48 PM *To:* akshay kulkarni ; R help Mailing list *Subject:* Re: [R] on lexical scoping On 04/04/2023 9:56 a.m., akshay kulkarni wrote: Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. Why doesn't it look further in the environment stack, like that of packages? There are thousands of packages that contain the variable named x. Of course, that happens if the above code is in a function (or does it?). What concept of R is at work in this dichotomy? First, some background: Packages are associated with multiple environments. There is the internal one that the package sees, and the external one that contains just the exports. These are sometimes called the "package" environment and the "namespace" environment, but I don't think those names are used consistently. (There's another one containing the imports, but for these purposes, it's indistinguishable from the internal one.) When a package is loaded by loadNamespace("pkg"), nothing happens in the global environment: no new variables are visible. When it is attached by library("pkg"), a lot more happens. First, it is loaded as above, then the search list is modified. The global environment is entry 1 in the search list; it stays there, but its "parent" is set to a copy of the external environment from the new package, and the parent of that environment is set to the previous parent, the second entry in the search list. Okay, so now you search for "x" in the global environment, and it's not there. It then goes to the other entries in the search list, which are typically external environments from various packages. None of those packages export "x", so it is not found. It doesn't matter if those packages use "x" without exporting it, because R won't look at internal environments in this kind of search. And it doesn't matter what happens in other packages that are not on the search list (i.e. not "attached" because you never called library() or require() on them), because they just aren't in the chain of environments where R looks. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] on lexical scoping....
On 04/04/2023 9:56 a.m., akshay kulkarni wrote: Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. Why doesn't it look further in the environment stack, like that of packages? There are thousands of packages that contain the variable named x. Of course, that happens if the above code is in a function (or does it?). What concept of R is at work in this dichotomy? First, some background: Packages are associated with multiple environments. There is the internal one that the package sees, and the external one that contains just the exports. These are sometimes called the "package" environment and the "namespace" environment, but I don't think those names are used consistently. (There's another one containing the imports, but for these purposes, it's indistinguishable from the internal one.) When a package is loaded by loadNamespace("pkg"), nothing happens in the global environment: no new variables are visible. When it is attached by library("pkg"), a lot more happens. First, it is loaded as above, then the search list is modified. The global environment is entry 1 in the search list; it stays there, but its "parent" is set to a copy of the external environment from the new package, and the parent of that environment is set to the previous parent, the second entry in the search list. Okay, so now you search for "x" in the global environment, and it's not there. It then goes to the other entries in the search list, which are typically external environments from various packages. None of those packages export "x", so it is not found. It doesn't matter if those packages use "x" without exporting it, because R won't look at internal environments in this kind of search. And it doesn't matter what happens in other packages that are not on the search list (i.e. not "attached" because you never called library() or require() on them), because they just aren't in the chain of environments where R looks. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] weird things in seqMK() and sqmk()
There are references listed on the help page for seqMK. I'd start with those. If you can't figure it out from that, then contacting the pheno package maintainer or author of the package would probably be the best step. This group really isn't set up for supporting contributed packages, though sometimes knowledgeable people here will comment. Duncan Murdoch On 01/04/2023 2:05 p.m., Nick Wray wrote: Hello The other say I posted a question about altering confidence limits in the seqMK() function in the pheno package. I didn't get any bites but in any case I've been trying to use this function. It seems to me to give very odd results - sometimes identifying 8 or 9 changepoints in a relatively short vector of maybe 40 elements, and at other times not giving any changepoints at all, despite visually there appearing to be changepoints and other changepoint algorithms (pettitt etc) saying that there are other changepoints. Apart from the cran vignette there doesn't seem to be anything on this function Has anyone else used the seqMK() function and if so, have they noticed any weird behaviour with it? I've also lookedf at sqmk() in trendchange function. This also seems to give odd results, and not ones consistent with seqMK() results either Again has anyone used these and do they know of any sites with further ifo, as it seems v sparse about these two functions Thanks Nick Wray [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Displaying Dichotomous Variables as fractions in gtsummary Tables
I think questions about gtsummary are better addressed to that project. They have a link "Getting Help" on their web page; I'd start there: https://www.danieldsjoberg.com/gtsummary/SUPPORT.html Duncan Murdoch On 27/03/2023 2:19 p.m., Deramus, Thomas Patrick wrote: Hi R Experts. Apologies if this has been shared elsewhere, but I haven't been able to find a solid answer to this. I'm wanting to create a table in gtsummary that displays entries for "Yes" and "No" as fractions rather than a relative to the total (e.g. {n} / {N} in the documentation). I realize I can split them into rows with something like: type = all_dichotomous() ~ "categorical" But I would honestly much rather display the variable as something like: Condition? (Y/N) count "Yes"/ count "No" Is this possible to do in gtsummary? Thank you in advance. The information in this e-mail is intended only for th...{{dropped:8}} __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] printing a data.frame without row numbers
print(data.frame(COL1=1:5, COL2=10:6), row.names=FALSE) On 27/03/2023 1:05 p.m., Dennis Fisher wrote: R 4.2.3 OS X Colleagues, I am printing a large number of tables using the print command. A simple example is: print(data.frame(COL1=1:5, COL2=10:6)) The result in this case is: COL1 COL2 11 10 229 338 447 556 I would like to print the table WITHOUT the row numbers: COL1 COL2 1 10 29 38 47 56 Is there any simple way to accomplish this, short of writing my own print method or outputting line-by-line using cat? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rprofile.site and automatic installation of missing packages
On 21/03/2023 9:58 a.m., PIKAL Petr wrote: Hallo Duncan Tested but does not work so something other must be wrong. R version 4.2.2. installed.packages()[,"Package"] base boot classcluster codetools compiler datasetsforeign graphics grDevices grid KernSmooth "base" "boot""class" "cluster""codetools" "compiler" "datasets" "foreign" "graphics""grDevices" "grid" "KernSmooth" lattice MASS Matrixmethods mgcv nlme nnet parallel rpartspatial splines stats "lattice" "MASS" "Matrix" "methods" "mgcv" "nlme" "nnet" "parallel""rpart" "spatial" "splines""stats" stats4 survival tcltk tools translations utils "stats4" "survival""tcltk""tools" "translations" "utils" My Rprofile.site # Things you might want to change options(papersize="a4") options(help_type="html") library(utils) library(MASS) #** test <-(scan("pack.txt", character(), quote = "")) x<- utils::installed.packages() utils::install.packages(test[!test %in% x], repos="https://cloud.r-project.org;) ##** Options are set and working. MASS should be loaded but is not search() [1] ".GlobalEnv""package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base" Any suggestion where to look? I'd add code to print the values of x and test to confirm that things are proceeding as you expect. I don't know if print() or cat() will work there; you might need to use message(). For attaching packages, you should see ?Startup again: this is done via options() or an environment variable, not library() calls in the profile file. Duncan Murdoch Best regards Petr -Original Message- From: Duncan Murdoch Sent: Tuesday, March 21, 2023 1:55 PM To: PIKAL Petr ; r-help Subject: Re: [R] Rprofile.site and automatic installation of missing packages ?Startup says: "Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned." So you need utils::installed.packages and utils::install.packages . Duncan Murdoch On 21/03/2023 8:04 a.m., PIKAL Petr wrote: Dear all. I am trying to install missing (not installed) packages during startup of R through code in Rprofile.site but I miserably failed and I am not sure what I am doing wrong. R is installed to C:Program files but it is not writable for the users, therefore I cannot change Rprofile.site located in root etc directory. I however can put Rprofile.site in users home directory (Documents) and use it for R startup setting (partly). However I want for less experienced users to put a code here to check installed packages, check if some specified set of packages is installed and install them, but it is not working. The code in Rprofile.site is: #** test <- scan("pack.txt", character(), quote = "") inst <- installed.packages() install.packages(test[!test %in% inst], repos="https://cloud.r-project.org;) #** An example of pack.txt is e.g. ggplot2 zoo but the code is not executed and packages are not installed. If I use this code after R starts, everything is OK and packages are installed to Sys.getenv("R_LIBS_USER") [1] "C:\\Users\\PikalP\\AppData\\Local/R/win-library/4.2" The same applies if I put e.g. library(MASS) in the Rprofile.site, the package is not loaded but after R is live, library(MASS) loads a package. So my question is What is the best way to check after fresh R installation if some predefined set of packages is installed and if not, perform an installation without user intervention in Windows environment? S pozdravem | Best Regards Petr __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Osobní úd
Re: [R] Rprofile.site and automatic installation of missing packages
?Startup says: "Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned." So you need utils::installed.packages and utils::install.packages . Duncan Murdoch On 21/03/2023 8:04 a.m., PIKAL Petr wrote: Dear all. I am trying to install missing (not installed) packages during startup of R through code in Rprofile.site but I miserably failed and I am not sure what I am doing wrong. R is installed to C:Program files but it is not writable for the users, therefore I cannot change Rprofile.site located in root etc directory. I however can put Rprofile.site in users home directory (Documents) and use it for R startup setting (partly). However I want for less experienced users to put a code here to check installed packages, check if some specified set of packages is installed and install them, but it is not working. The code in Rprofile.site is: #** test <- scan("pack.txt", character(), quote = "") inst <- installed.packages() install.packages(test[!test %in% inst], repos="https://cloud.r-project.org;) #** An example of pack.txt is e.g. ggplot2 zoo but the code is not executed and packages are not installed. If I use this code after R starts, everything is OK and packages are installed to Sys.getenv("R_LIBS_USER") [1] "C:\\Users\\PikalP\\AppData\\Local/R/win-library/4.2" The same applies if I put e.g. library(MASS) in the Rprofile.site, the package is not loaded but after R is live, library(MASS) loads a package. So my question is What is the best way to check after fresh R installation if some predefined set of packages is installed and if not, perform an installation without user intervention in Windows environment? S pozdravem | Best Regards Petr __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lexical scoping for scripts......
On 19/03/2023 2:55 p.m., akshay kulkarni wrote: Dear Duncun, What if there is no interactive "session" running? I will be running my scripts automatically from crontab in Linux. I was talking about the session that is created for the duration of the BATCH run, not some other session that may be running in another process. Sorry for the confusion. Duncan Murdoch THanking you, Yours sincerely, AKSHAY M KULKARNI ---- *From:* Duncan Murdoch *Sent:* Monday, March 20, 2023 12:20 AM *To:* akshay kulkarni ; R help Mailing list *Subject:* Re: [R] lexical scoping for scripts.. On 19/03/2023 2:33 p.m., akshay kulkarni wrote: Dear Duncun, thanks for the reply So when I run a script in the system command line by R CMD BATCH, the objects created in the script cannot be stored in the workspace ,right? If yes, how to save them? Moreover, the only way to save the objects CREATED from the script permanently is to save them to the disk, right? The objects you create *will* appear in the workspace of the session that's running. They won't be saved to disk automatically so they'll disappear at the end of the BATCH run. You can use various functions (save(), save.image(), saveRDS(), writeLines(), etc.) to write them to disk if you don't want them to disappear. Duncan Murdoch THanking you, yours sincerely, AKSHAY M KULKARNI ---- *From:* Duncan Murdoch *Sent:* Saturday, March 18, 2023 11:49 PM *To:* akshay kulkarni ; R help Mailing list *Subject:* Re: [R] lexical scoping for scripts.. On 18/03/2023 1:57 p.m., akshay kulkarni wrote: Dear members, The documentation for source() says: Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. What does this mean? I presume that any objects that are CREATED by the script are stored in the Global environment (if local = FALSE), but the rules for lexical scoping are the same as for functions, right? No, assignments will happen in the "chosen environment" as well. I'm not sure exactly what you mean about the rules for lexical scoping, but I think the answer is yes. So if you do the following: Put this code in a file named "f.R": x <- 123 f <- function() x and you run this code in your global environment: x <- 456 e <- new.env() source("f.R", local = e) Then you'll find that x retains the value 456, and e$f() returns 123. Does the same apply for running the same script from the system command line by R CMD BATCH? I don't think R CMD BATCH has any equivalent to the local argument. Everything is evaluated in the global environment. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lexical scoping for scripts......
On 19/03/2023 2:33 p.m., akshay kulkarni wrote: Dear Duncun, thanks for the reply So when I run a script in the system command line by R CMD BATCH, the objects created in the script cannot be stored in the workspace ,right? If yes, how to save them? Moreover, the only way to save the objects CREATED from the script permanently is to save them to the disk, right? The objects you create *will* appear in the workspace of the session that's running. They won't be saved to disk automatically so they'll disappear at the end of the BATCH run. You can use various functions (save(), save.image(), saveRDS(), writeLines(), etc.) to write them to disk if you don't want them to disappear. Duncan Murdoch THanking you, yours sincerely, AKSHAY M KULKARNI *From:* Duncan Murdoch *Sent:* Saturday, March 18, 2023 11:49 PM *To:* akshay kulkarni ; R help Mailing list *Subject:* Re: [R] lexical scoping for scripts.. On 18/03/2023 1:57 p.m., akshay kulkarni wrote: Dear members, The documentation for source() says: Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. What does this mean? I presume that any objects that are CREATED by the script are stored in the Global environment (if local = FALSE), but the rules for lexical scoping are the same as for functions, right? No, assignments will happen in the "chosen environment" as well. I'm not sure exactly what you mean about the rules for lexical scoping, but I think the answer is yes. So if you do the following: Put this code in a file named "f.R": x <- 123 f <- function() x and you run this code in your global environment: x <- 456 e <- new.env() source("f.R", local = e) Then you'll find that x retains the value 456, and e$f() returns 123. Does the same apply for running the same script from the system command line by R CMD BATCH? I don't think R CMD BATCH has any equivalent to the local argument. Everything is evaluated in the global environment. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lexical scoping for scripts......
On 18/03/2023 1:57 p.m., akshay kulkarni wrote: Dear members, The documentation for source() says: Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. What does this mean? I presume that any objects that are CREATED by the script are stored in the Global environment (if local = FALSE), but the rules for lexical scoping are the same as for functions, right? No, assignments will happen in the "chosen environment" as well. I'm not sure exactly what you mean about the rules for lexical scoping, but I think the answer is yes. So if you do the following: Put this code in a file named "f.R": x <- 123 f <- function() x and you run this code in your global environment: x <- 456 e <- new.env() source("f.R", local = e) Then you'll find that x retains the value 456, and e$f() returns 123. Does the same apply for running the same script from the system command line by R CMD BATCH? I don't think R CMD BATCH has any equivalent to the local argument. Everything is evaluated in the global environment. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] null in rao.test in R
On 11/03/2023 9:21 a.m., Nick Wray wrote: Hello I am testing for the homogeneity of clusters of (yearly) seasonal data using the rao.test from the circular package. I can't find anywhere (including the Cran pages) which specifically mentions the null hypothesis for this test. Playing around with it, for example using say the toy code beneath it would seem that the null is that the data sets tested are not homogenous, which is fine except that seems to be contrary to normal practice, where the null would be that the two sets are homogenous unless there's evidence otherwise. Has anyone else used this test and can confirm that the null is that sets are not homogenous? a<-2*pi*c(1,2,3)/365 b<-a+pi rt<- rao.test(a,b) rt$p.value this gives two p-values of 1 - one for the equality of polar vectors, and the second for the test of equality of dispersions. Although I can guess, to be honest at the moment i'm not sure what either of these things mean (not really an R-help question I know) as I've only just begun serious analysis of circular data but I am surprised that this toy data gives a p-value of 1 in each case can anyone cast light on all this? I think the null for the polar test is that the directions are the same, and the null for the dispersion test is that the dispersions are the same. Your two samples are very similar but in opposite directions. If you add pi/2 (or other numbers) instead of pi to form b from a, you'll see very small p values. What this indicates to me is that the test as implemented is unable to detect directions that differ by pi. I don't know whether the original test had this limitation or whether it isn't implemented as designed. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Palettes {grDevices} - wrong number of colors returned?
On 23/02/2023 6:09 a.m., Achim Zeileis wrote: Duncan, thanks for your feedback. I just received your response after sending out mine. You came to the same conclusion. Should I prepare a patch and send it to you so that you can also have a look? Or view Bugzilla? Copying Sigbert's message to Bugzilla is a good idea so it can be referred to from the NEWS entry. If you want to submit a patch along with it, let me know and I'll take a look at it. Duncan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Palettes {grDevices} - wrong number of colors returned?
On 23/02/2023 4:36 a.m., Sigbert Klinke wrote: Hi, I would have expected that I get always 3 colors as result which is not true: hcl.colors(3, alpha=c(0, 0.5, 1)) # 3 colors rainbow(3, alpha=c(0, 0.5, 1))# 3 colors heat.colors(3, alpha=c(0, 0.5, 1))# 3 colors terrain.colors(3, alpha=c(0, 0.5, 1)) # 6 colors cm.colors(3, alpha=c(0, 0.5, 1)) # 6 colors topo.colors(3, alpha=c(0, 0.5, 1))# 9 colors R-Version and platform: R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) Bug or feature? Looks like a bug to me, they should all be length 3. The reason it happens in terrain.colors (I didn't look at the others) is that it breaks the range into two parts, and relies on the number of values of the parameters in each part to get the length, but passes the full alpha vector in: terrain.colors <- function (n, alpha, rev = FALSE) { if ((n <- as.integer(n[1L])) > 0) { k <- n%/%2 h <- c(4/12, 2/12, 0/12) s <- c(1, 1, 0) v <- c(0.65, 0.9, 0.95) cols <- c(hsv(h = seq.int(h[1L], h[2L], length.out = k), s = seq.int(s[1L], s[2L], length.out = k), v = seq.int(v[1L], v[2L], length.out = k), alpha = alpha), hsv(h = seq.int(h[2L], h[3L], length.out = n - k + 1)[-1L], s = seq.int(s[2L], s[3L], length.out = n - k + 1)[-1L], v = seq.int(v[2L], v[3L], length.out = n - k + 1)[-1L], alpha = alpha)) if(rev) rev(cols) else cols } else character() } A bug fix would be to recycle alpha to the right length and only pass in portions of it, e.g. terrain.colors <- function (n, alpha, rev = FALSE) { if ((n <- as.integer(n[1L])) > 0) { alpha <- rep_len(alpha, length.out = n) k <- n%/%2 h <- c(4/12, 2/12, 0/12) s <- c(1, 1, 0) v <- c(0.65, 0.9, 0.95) cols <- c(hsv(h = seq.int(h[1L], h[2L], length.out = k), s = seq.int(s[1L], s[2L], length.out = k), v = seq.int(v[1L], v[2L], length.out = k), alpha = alpha[seq_len(k)]), hsv(h = seq.int(h[2L], h[3L], length.out = n - k + 1)[-1L], s = seq.int(s[2L], s[3L], length.out = n - k + 1)[-1L], v = seq.int(v[2L], v[3L], length.out = n - k + 1)[-1L], alpha = alpha[seq_len(n - k) + k])) if(rev) rev(cols) else cols } else character() } I'd guess the same sort of approach would fix cm.colors and topo.colors. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting data using subset function
On 05/02/2023 2:59 p.m., Rolf Turner wrote: On Sun, 5 Feb 2023 19:37:03 +0530 Upananda Pani wrote: Dear All, I want to create a vector p and extract first 20 observations using subset function based on logical condition. My code is below p <- 0:100 I know i can extract the first 20 observations using the following command. q <- p[1:20] But I want to extract the first 20 observations using subset function which requires a logical condition. I am not able to frame the logical condition. The code should be q <- subset(p, logical condition) I am not able to do it. Please let me know what you think. I think that you are manufacturing an unnecessary difficulty. If you want the first 20 entries of p, use p[1:20]!!! However, if you obdurately *insist* on using subset() you could do subset(p,(1:length(p)) <= 20) This works, but makes a mountain out of a molehill. Just to build the mountain a little higher, I would use subset(p, seq_along(p) <= 20) You should generally avoid expressions like "1:length(p)", because they don't do what you would expect in the unusual case that p is length 0. Even in cases where you know p is not length 0, it's a good habit to get into so that in the future you don't get surprised. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Detpack package
On 01/02/2023 11:41 a.m., Nick Wray wrote: I did use "detpack" ie not with a capital detpack::chi2testuniform(vals,0.05) gives this: Error: 'chi2testuniform' is not an exported object from 'namespace:detpack' ?? Thanks Nick The only exports from detpack are these: > library(detpack) > ls(2) [1] "det.construct" "det.cut" "det.de""det.leafs" "det.query" "det.rnd" "det1" [8] "det2" It looks as though the author of detpack documented chi2testuniform, but forgot to export it. You can see the source of the version on CRAN here: https://github.com/cran/detpack The author used Roxygen2, but apparently forgot to say @export before that function (and some others). The package tests perfectly OK on CRAN, because none of the examples made it into the help pages, where they would have failed. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dyn.load(now = FALSE) not actually lazy?
According to the help page for dyn.load, I think this is within the allowed behaviour: "now: a logical controlling whether all symbols are resolved (and relocated) immediately the library is loaded or deferred until they are used. This control is useful for developers testing whether a library is complete and has all the necessary symbols, and for users to ignore missing symbols. Whether this has any effect is system-dependent." It appears to be intended for a DLL that doesn't define all the symbols that your program will use, not for a DLL that has external references that can't be resolved. And there's that last sentence. I think for what you want, you'd have to write the DLL (i.e. libtorch) in such a way that it does delayed loading of its dependencies. Duncan Murdoch On 31/01/2023 10:16 p.m., Michael Milton wrote: On Linux, if I have a .so file that has a dependency on another .so, and I `dyn.load(now=FALSE)` the first one, R seems to try to resolve the symbols immediately, causing the load to fail. For example, I have `libtorch` installed on my HPC. Note that it links to various libs such as `libcudart.so` and `libmkl_intel_lp64.so.2` which aren't currently in my library path: ➜ ~ ldd /stornext/System/data/nvidia/libtorch-gpu/libtorch-gpu-1.12.1/lib/libtorch_cpu.so linux-vdso.so.1 => (0x7ffcab58c000) libgomp.so.1 => /stornext/System/data/apps/gcc/gcc-11.2.0/lib64/libgomp.so.1 (0x7f8cb22bf000) libpthread.so.0 => /lib64/libpthread.so.0 (0x7f8cb20a3000) libc10.so => /stornext/System/data/nvidia/libtorch-gpu/libtorch-gpu-1.12.1/lib/libc10.so (0x7f8cb1e2d000) libnuma.so.1 => /lib64/libnuma.so.1 (0x7f8cb1c21000) librt.so.1 => /lib64/librt.so.1 (0x7f8cb1a19000) libgcc_s.so.1 => /stornext/System/data/apps/gcc/gcc-11.2.0/lib64/libgcc_s.so.1 (0x7f8cb1801000) libdl.so.2 => /lib64/libdl.so.2 (0x7f8cb15fd000) libmkl_intel_lp64.so.2 => not found libmkl_gnu_thread.so.2 => not found libmkl_core.so.2 => not found libm.so.6 => /lib64/libm.so.6 (0x7f8cb12fb000) libcudart.so.11.0 => not found Then in R, if I try to load that same file: dyn.load("/stornext/System/data/nvidia/libtorch-gpu/libtorch-gpu-1.12.1/lib/libtorch_cpu.so", now=FALSE) Error in dyn.load("/stornext/System/data/nvidia/libtorch-gpu/libtorch-gpu-1.12.1/lib/libtorch_cpu.so", : unable to load shared object '/stornext/System/data/nvidia/libtorch-gpu/libtorch-gpu-1.12.1/lib/libtorch_cpu.so': libmkl_intel_lp64.so.2: cannot open shared object file: No such file or directory Is this a bug in the `dyn.load` implementation for R? If not, why is it behaving like this? What should I do about it? For reference, I'm on CentOS 7, with Linux kernel 3.10.0-1160.81.1.el7.x86_64. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bug in internal 'tar' implementation?
Or directly to bugs.r-project.org . It definitely looks to me like a bug. Instructions for bug reports are here: https://www.r-project.org/bugs.html . David might need to set up a Bugzilla account according to those instructions before reporting. Duncan Murdoch On 31/01/2023 1:40 p.m., Bert Gunter wrote: This post should probably go to R-devel rather than here. -- Bert On Tue, Jan 31, 2023 at 9:47 AM David Engster wrote: I think I found a bug in the internal implementation of 'tar', but before bothering the R maintainers, I was advised to ask here to make sure I'm not missing something. Fortunately, it can be very easily reproduced on a Linux system. In an empty temporary directory, execute the following code: cat("foobar", file="test.txt") file.symlink("test.txt", "test_link.txt") tar("test.tar", c("test_link.txt", "test.txt"), tar="internal") system2("tar", c("tf", "test.tar")) This file create a file "test.txt" and a symbolic link "test_link.txt" pointing to that file. Those two are then put into "test.tar" using R's internal tar implementation, and then the system's 'tar' binary (usually GNU tar) will be used to display the contents of that archive. On my system (Debian 11, GNU tar 1.34), this gives me the following output: [1] TRUE test_link.txt tar: Skipping to next header tar: Exiting with failure status due to previous errors Not that *extracting* the archive with 'tar xf' (fortunately) works fine, it's just displaying its contents that fails. After looking into the hexdump of 'test.tar' and R's internal tar() code, I found out the reason for this is that a wrong size for the link is put into the tar header: it should be zero, but the size of the linked file is put in there instead. This leads to 'tar tf' jumping over too many blocks after displaying the link filename and hence aborting. While I'm aware the 'tar()' help says to avoid links for portability reasons, it also says that it supports symbolic links on OSes that support them, which Linux of course does, so do you agree this should be fixed? (It's a very simple one-line change.) Best, David __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] akima interp results to zero with less than 10 values
The akima package has a problematic license (it doesn't allow commercial use), so it's been recommended that people use the interp package instead. When I use interp::interp instead of akima::interp, I get reasonable output from your example. So that's another reason to drop akima... Duncan Murdoch On 26/01/2023 9:35 a.m., PIKAL Petr wrote: Dear all I have this table dput(mat) mat <- structure(c(2, 16, 9, 2, 16, 1, 1, 4, 7, 7, 44.52, 42.8, 43.54, 40.26, 40.09), dim = c(5L, 3L)) And I want to calculate result for contour or image plots as I did few years ago. However interp does not compute the z values and gives me zeros in z matrix. library(akima) interp(mat[,1], mat[,2], mat[, 3], nx=5, ny=5) $x [1] 2.0 5.5 9.0 12.5 16.0 $y [1] 1.0 2.5 4.0 5.5 7.0 $z [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]00000 [3,]00000 [4,]00000 [5,]00000 With the example from help page if less than 10 values are used, the result is also zero interp(akima$x[1:9], akima$y[1:9], akima$z[1:9], nx=5, ny=5) but with 10 or more values the result is correctly calculated interp(akima$x[1:10], akima$y[1:10], akima$z[1:10], nx=5, ny=5) $x [1] 0. 6.1625 12.3250 18.4875 24.6500 $y [1] 1.24 5.93 10.62 15.31 20.00 $z [,1] [,2] [,3] [,4] [,5] [1,] NA NA NA NA 34.6 [2,] NA NA 27.29139 27.11807 26.60971 [3,] NA 19.81371 19.63614 19.12778 18.61943 [4,] NA 14.01443 10.66531 11.13750 10.62914 [5,] NA NA NA NA NA Help page says x, y, and z must be the same length (execpt if x is a SpatialPointsDataFrame) and may contain no fewer than ***four*** points. So my understanding was that 5 poins could be used but I am obviously wrong. Is it a bug in interp or in the documentation or is it my poor understanding of the whole matter. Best regards Petr __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.