From re|chm@nj @end|ng |rom @bcg|ob@|@net Fri Aug 1 04:18:09 2025 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Thu, 31 Jul 2025 21:18:09 -0500 Subject: [R] Problem with function gp in package cccp In-Reply-To: References: Message-ID: <00c901dc028a$86916450$93b42cf0$@sbcglobal.net> In gp(F0, g0, A = A, b = b) : No restrictions provided, trying solve() This likely means that while you've specified A and b, the solver doesn't recognize any inequality (<=) or equality (=) restrictions - because in the context of the gp() function from the CVXR or similar geometric programming libraries in R, you're expected to provide explicit inequality/equality markers or properly formatted constraint matrices. So what's missing? Probably an argument like ineq = ... or eq = ... to declare the type of constraint. Here's how to express your constraint properly, assuming the library expects inequalities or equalities to be marked explicitly: # Properly declare equality constraints gp(F0, g0, eq=A, eq.b=b) Or possibly (depending on the package): gp(F0, g0, Aeq=A, beq=b) If the solver expects inequality constraints: gp(F0, g0, A=A, b=b, meq=1) # Indicating 1 equality constraint Jeff Reichman -----Original Message----- From: R-help On Behalf Of koller at science.iwi.ac.at Sent: Wednesday, July 30, 2025 2:32 PM To: r-help at r-project.org Subject: [R] Problem with function gp in package cccp Dear all! I tried to solve a simple test example of a geometric program: minimize x + y s.t. xy = 1 The solution should be (1, 1). I tried: F0 <- diag(2) # [m * n] m = number of terms of the posynomial, n = number of variables g0 <- log(matrix(1,2,1)) # [m * 1] A <- matrix(c(1,1), 1, 2) # one constraint, one row b <- log(matrix(1,1,1)) RES <- gp(F0, g0, A=A, b=b) Though I received the correct solution, the function gives a warning: In gp(F0, g0, A = A, b = b) : No restrictions provided, trying solve(). Also, when I try RES <- gp(F0, g0, A="A", b=b) or gp(F0, g0) receiving the same result, I find out, that my equality constraints are not considered at all. In my view, the unconstraint problem should have (0, 0) as a solution, btw. Am I missing something fundamental? Thanks in advance! Wolfgang [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From tg@77m @end|ng |rom y@hoo@com Fri Aug 1 16:30:37 2025 From: tg@77m @end|ng |rom y@hoo@com (Thomas Subia) Date: Fri, 1 Aug 2025 14:30:37 +0000 (UTC) Subject: [R] ggplot with arrows References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> Message-ID: <1901631158.894125.1754058637556@mail.yahoo.com> Consider: x <- seq(-5,5,length.out = 100) y <- x^2 data <- data.frame(x,y) library(ggplot2) ggplot(data,aes(x,y))+ ? stat_function( ? ? fun = function(x) x^2, ? ? color = "blue", linewidth = 1.25 ? ) + ? theme_linedraw() I'd like to add an arrow to the ends of curve to illustrate the?curve continues indefinitely in that direction, ChatGPT suggests using geom_segment or geom_link but there has an easier way to do this. Any suggestions would be appreciated. [[alternative HTML version deleted]] From tebert @end|ng |rom u||@edu Fri Aug 1 16:43:34 2025 From: tebert @end|ng |rom u||@edu (Ebert,Timothy Aaron) Date: Fri, 1 Aug 2025 14:43:34 +0000 Subject: [R] ggplot with arrows In-Reply-To: <1901631158.894125.1754058637556@mail.yahoo.com> References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> Message-ID: I would save the graph as a PowerPoint object and then edit it in PowerPoint. library(ggplot2) library(grid) library(officer) library(rvg) x <- seq(-5, 5, length.out = 100) y <- x^2 data <- data.frame(x, y) plot <- ggplot(data, aes(x, y)) + geom_path(color = "blue", linewidth = 1.25) + geom_segment( aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), arrow = arrow(angle = 20, type = "closed", ends = "both", length = unit(0.2, "inches")), color = "red" ) + theme_linedraw() doc <- read_pptx() doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme") doc <- ph_with(doc, dml(ggobj = plot), location = ph_location_fullsize()) print(doc, target = "quadratic_with_arrows.pptx") If I remember I think you have to ungroup it in PowerPoint and then all elements become editable. The general approach can be done with other file formats/programs, not just PowerPoint. Tim -----Original Message----- From: R-help On Behalf Of Thomas Subia via R-help Sent: Friday, August 1, 2025 10:31 AM To: r-help at r-project.org Subject: [R] ggplot with arrows [External Email] Consider: x <- seq(-5,5,length.out = 100) y <- x^2 data <- data.frame(x,y) library(ggplot2) ggplot(data,aes(x,y))+ stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25 ) + theme_linedraw() I'd like to add an arrow to the ends of curve to illustrate the curve continues indefinitely in that direction, ChatGPT suggests using geom_segment or geom_link but there has an easier way to do this. Any suggestions would be appreciated. [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From @vi@e@gross m@iii@g oii gm@ii@com Fri Aug 1 17:04:55 2025 From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com) Date: Fri, 1 Aug 2025 11:04:55 -0400 Subject: [R] ggplot with arrows In-Reply-To: References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> Message-ID: <006701dc02f5$a3e68970$ebb39c50$@gmail.com> For some, the purist perspective is to automate a process using a single tool. Some see it as pure to use a series of (often smaller and more focused set of) tools that together do the job. In a sense, ggplot is closer to the latter with endless extensions you can add in to tweak a result and sometimes people stand on their heads to do something that could be done with less effort by a technique like switching mid-way to another tool, perhaps with a manual component. The suggestion by Tim is reasonable and, as he notes, common enough especially for one-time projects or people who are not as great at R programming as using other tools like PowerPoint or EXCEL. And, sometimes you have to hand your work to a client who wants to adjust things just so using the tool of their choice, including playing with fonts or where to wrap text or position things more precisely. Of course, if you do things repeatedly such as make a new graph every day with more data, it gets annoying to have to step out each time and take a saved file and open it anew and ... -----Original Message----- From: R-help On Behalf Of Ebert,Timothy Aaron Sent: Friday, August 1, 2025 10:44 AM To: Thomas Subia ; r-help at r-project.org Subject: Re: [R] ggplot with arrows I would save the graph as a PowerPoint object and then edit it in PowerPoint. library(ggplot2) library(grid) library(officer) library(rvg) x <- seq(-5, 5, length.out = 100) y <- x^2 data <- data.frame(x, y) plot <- ggplot(data, aes(x, y)) + geom_path(color = "blue", linewidth = 1.25) + geom_segment( aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), arrow = arrow(angle = 20, type = "closed", ends = "both", length = unit(0.2, "inches")), color = "red" ) + theme_linedraw() doc <- read_pptx() doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme") doc <- ph_with(doc, dml(ggobj = plot), location = ph_location_fullsize()) print(doc, target = "quadratic_with_arrows.pptx") If I remember I think you have to ungroup it in PowerPoint and then all elements become editable. The general approach can be done with other file formats/programs, not just PowerPoint. Tim -----Original Message----- From: R-help On Behalf Of Thomas Subia via R-help Sent: Friday, August 1, 2025 10:31 AM To: r-help at r-project.org Subject: [R] ggplot with arrows [External Email] Consider: x <- seq(-5,5,length.out = 100) y <- x^2 data <- data.frame(x,y) library(ggplot2) ggplot(data,aes(x,y))+ stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25 ) + theme_linedraw() I'd like to add an arrow to the ends of curve to illustrate the curve continues indefinitely in that direction, ChatGPT suggests using geom_segment or geom_link but there has an easier way to do this. Any suggestions would be appreciated. [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From ru|pb@rr@d@@ @end|ng |rom @@po@pt Fri Aug 1 17:15:21 2025 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Fri, 1 Aug 2025 16:15:21 +0100 Subject: [R] ggplot with arrows In-Reply-To: References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> Message-ID: On 8/1/2025 3:43 PM, Ebert,Timothy Aaron wrote: > I would save the graph as a PowerPoint object and then edit it in PowerPoint. > library(ggplot2) > library(grid) > library(officer) > library(rvg) > x <- seq(-5, 5, length.out = 100) > y <- x^2 > data <- data.frame(x, y) > plot <- ggplot(data, aes(x, y)) + > geom_path(color = "blue", linewidth = 1.25) + > geom_segment( > aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), > arrow = arrow(angle = 20, type = "closed", ends = "both", length = unit(0.2, "inches")), > color = "red" > ) + > theme_linedraw() > doc <- read_pptx() > doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme") > doc <- ph_with(doc, dml(ggobj = plot), location = ph_location_fullsize()) > print(doc, target = "quadratic_with_arrows.pptx") > > If I remember I think you have to ungroup it in PowerPoint and then all elements become editable. The general approach can be done with other file formats/programs, not just PowerPoint. > Tim > > -----Original Message----- > From: R-help On Behalf Of Thomas Subia via R-help > Sent: Friday, August 1, 2025 10:31 AM > To: r-help at r-project.org > Subject: [R] ggplot with arrows > > [External Email] > > Consider: > > x <- seq(-5,5,length.out = 100) > y <- x^2 > data <- data.frame(x,y) > library(ggplot2) > ggplot(data,aes(x,y))+ > stat_function( > fun = function(x) x^2, > color = "blue", linewidth = 1.25 > ) + > theme_linedraw() > I'd like to add an arrow to the ends of curve to illustrate the curve continues indefinitely in that direction, ChatGPT suggests using geom_segment or geom_link but there has an easier way to do this. > > Any suggestions would be appreciated. > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.r-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. Hello, First of all, according to the documentation ?stat_function, section Arguments, data Ignored by stat_function(), do not use. As for the arrows, first get the equations of the lines tangent to the end points of the parabola, y = -10*x - 25 y = 10*x - 25 then compute segments' end points and plot. f <- function(x, b = -25, m) m*x + b arrow_data <- data.frame( id = c("n", "p"), x = c(-5, 5), y = f(c(-5, 5), m = c(-10, 10)), xend = c(-6, 6), yend = f(c(-6, 6), m = c(-10, 10)) ) ggplot() + stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25, xlim = c(-5, 5) ) + geom_segment( data = arrow_data, mapping = aes(x = x, y = y, xend = xend, yend = yend, group = id), arrow = arrow(length = unit(0.5, "cm")), linewidth = 1.25, linetype = "dashed", inherit.aes = FALSE ) + theme_linedraw() Remove linetype and add color if you want. Hope this helps, Rui Barradas From ru|pb@rr@d@@ @end|ng |rom @@po@pt Fri Aug 1 17:24:54 2025 From: ru|pb@rr@d@@ @end|ng |rom @@po@pt (Rui Barradas) Date: Fri, 1 Aug 2025 16:24:54 +0100 Subject: [R] ggplot with arrows In-Reply-To: References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> Message-ID: <6d6113c1-caa8-4792-b98c-02d451b31e0f@sapo.pt> On 8/1/2025 4:15 PM, Rui Barradas wrote: > On 8/1/2025 3:43 PM, Ebert,Timothy Aaron wrote: >> I would save the graph as a PowerPoint object and then edit it in >> PowerPoint. >> library(ggplot2) >> library(grid) >> library(officer) >> library(rvg) >> x <- seq(-5, 5, length.out = 100) >> y <- x^2 >> data <- data.frame(x, y) >> plot <- ggplot(data, aes(x, y)) + >> ?? geom_path(color = "blue", linewidth = 1.25) + >> ?? geom_segment( >> ???? aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), >> ???? arrow = arrow(angle = 20, type = "closed", ends = "both", length >> = unit(0.2, "inches")), >> ???? color = "red" >> ?? ) + >> ?? theme_linedraw() >> doc <- read_pptx() >> doc <- add_slide(doc, layout = "Title and Content", master = "Office >> Theme") >> doc <- ph_with(doc, dml(ggobj = plot), location = ph_location_fullsize()) >> print(doc, target = "quadratic_with_arrows.pptx") >> >> If I remember I think you have to ungroup it in PowerPoint and then >> all elements become editable. The general approach can be done with >> other file formats/programs, not just PowerPoint. >> Tim >> >> -----Original Message----- >> From: R-help On Behalf Of Thomas Subia >> via R-help >> Sent: Friday, August 1, 2025 10:31 AM >> To: r-help at r-project.org >> Subject: [R] ggplot with arrows >> >> [External Email] >> >> Consider: >> >> x <- seq(-5,5,length.out = 100) >> y <- x^2 >> data <- data.frame(x,y) >> library(ggplot2) >> ggplot(data,aes(x,y))+ >> ?? stat_function( >> ???? fun = function(x) x^2, >> ???? color = "blue", linewidth = 1.25 >> ?? ) + >> ?? theme_linedraw() >> I'd like to add an arrow to the ends of curve to illustrate the curve >> continues indefinitely in that direction, ChatGPT suggests using >> geom_segment or geom_link but there has an easier way to do this. >> >> Any suggestions would be appreciated. >> >> >> ???????? [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide https://www.r-project.org/posting- >> guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide https://www.R-project.org/posting- >> guide.html >> and provide commented, minimal, self-contained, reproducible code. > Hello, > > First of all, according to the documentation ?stat_function, section > Arguments, > > > data > Ignored by stat_function(), do not use. > > > As for the arrows, first get the equations of the lines tangent to the > end points of the parabola, > > y = -10*x - 25 > y = 10*x - 25 > > then compute segments' end points and plot. > > > f <- function(x, b = -25, m) m*x + b > arrow_data <- data.frame( > ? id = c("n", "p"), > ? x = c(-5, 5), > ? y = f(c(-5, 5), m = c(-10, 10)), > ? xend = c(-6, 6), > ? yend = f(c(-6, 6), m = c(-10, 10)) > ) > > ggplot() + > ? stat_function( > ??? fun = function(x) x^2, > ??? color = "blue", linewidth = 1.25, > ??? xlim = c(-5, 5) > ? ) + > ? geom_segment( > ??? data = arrow_data, > ??? mapping = aes(x = x, y = y, xend = xend, yend = yend, group = id), > ??? arrow = arrow(length = unit(0.5, "cm")), > ??? linewidth = 1.25, > ??? linetype = "dashed", > ??? inherit.aes = FALSE > ? ) + > ? theme_linedraw() > > > > Remove linetype and add color if you want. > > Hope this helps, > > Rui Barradas > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. Hello, Sorry, my previous code is a bit messy. You don't need to group, so I removed 'id' from the arrow_data. It's better to define the arrows' end points x coordinates as variables, it makes it easier to change the plot at will. And the function is now defined with the intercept as last argument. f <- function(x, m, b = -25) m*x + b # here plot with linetype = "dashed" x0 <- c(-5, 5) x1 <- c(-6, 6) arrow_data <- data.frame( x = x0, y = f(x = x0, m = c(-10, 10)), xend = x1, yend = f(x = x1, m = c(-10, 10)) ) ggplot() + stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25, xlim = c(-5, 5) ) + geom_segment( data = arrow_data, mapping = aes(x = x, y = y, xend = xend, yend = yend), arrow = arrow(length = unit(0.5, "cm")), linewidth = 1.25, linetype = "dashed", inherit.aes = FALSE ) + theme_linedraw() #--- # here the line type is the default solid, so # start the arrows a bit away from the parabola, 0.1 away. x0 <- c(-5.1, 5.1) x1 <- c(-6, 6) arrow_data <- data.frame( x = x0, y = f(x = x0, m = c(-10, 10)), xend = x1, yend = f(x = x1, m = c(-10, 10)) ) ggplot() + stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25, xlim = c(-5, 5) ) + geom_segment( data = arrow_data, mapping = aes(x = x, y = y, xend = xend, yend = yend), arrow = arrow(length = unit(0.5, "cm")), linewidth = 1.25, inherit.aes = FALSE ) + theme_linedraw() Hope this helps, Rui Barradas From koiier m@iii@g oii scie@ce@iwi@@c@@t Fri Aug 1 17:39:30 2025 From: koiier m@iii@g oii scie@ce@iwi@@c@@t (koiier m@iii@g oii scie@ce@iwi@@c@@t) Date: Fri, 01 Aug 2025 17:39:30 +0200 Subject: [R] Problem with function gp in package cccp In-Reply-To: <00c901dc028a$86916450$93b42cf0$@sbcglobal.net> References: <00c901dc028a$86916450$93b42cf0$@sbcglobal.net> Message-ID: <1bec980f2452a04395dead6a26db1286@science.iwi.ac.at> Thank you, Jeff and Bert! 1. As to the unconstrained problem I gave (which is not my main concern) I should have added that in geometric programming it is assumed that the target variables are positive, thus x,y > 0. This would also rule out my given solution, (0, 0), of the unconstrained problem. The positivity constraint in geometric programming is a consequence of the role the logarithmic transformation plays in the theory of geometric programming. 2. However, my concern is to find out how to define equality constraints and submit them as an argument to gp(), so I wanted to try out the most simple case. But it seems as gp() implicitely assumes there must be at least inequality constraints. If I add inequality constraints, then my equality constraints are not ignored by gp(). So, in the following example, I added a non-binding inequality constraint, and I receive the correct solution, this time for the correct reasons: ## Minimise P + Q subject to P*Q = 1 and 0.5*P^(-1)*Q^(-1) <= 1 F0 <- diag(2) # [m0 * n] m0 = number of terms of the posynomial, n = number of variables g0 <- log(matrix(1,2,1)) # [m0 * 1] bexp <- 1 A <- matrix(c(1,1), 1, 2) # one constraint, one row b <- log(matrix(bexp, 1, 1)) F1 <- matrix(c(-1,-1), 1, 2) # additional (redundant) inequality constraint [m1 * n] m1 = number of terms of the posynomial g1 <- log(matrix(0.5*bexp, 1, 1)) # [m1 * 1] RES <- gp(F0, g0, FList=list(F1), gList=list(g1), A=A, b=b) sol <- RES$pdv$x c(sol) # [1] 1 1 RES <- gp(F0, g0, FList=list(F1), gList=list(g1)) # without the equality constraint sol <- RES$pdv$x c(sol) # [1] 0.7071069 0.7071069 Best regards, Wolfgang Am 2025-08-01 04:18, schrieb Jeff Reichman: > In gp(F0, g0, A = A, b = b) : No restrictions provided, trying solve() > > > This likely means that while you've specified A and b, the solver > doesn't > recognize any inequality (<=) or equality (=) restrictions - because in > the > context of the gp() function from the CVXR or similar geometric > programming > libraries in R, you're expected to provide explicit inequality/equality > markers or properly formatted constraint matrices. > > So what's missing? Probably an argument like ineq = ... or eq = ... to > declare the type of constraint. > > Here's how to express your constraint properly, assuming the library > expects > inequalities or equalities to be marked explicitly: > > # Properly declare equality constraints > gp(F0, g0, eq=A, eq.b=b) > > Or possibly (depending on the package): > > gp(F0, g0, Aeq=A, beq=b) > > If the solver expects inequality constraints: > > gp(F0, g0, A=A, b=b, meq=1) # Indicating 1 equality constraint > > Jeff Reichman > > > -----Original Message----- > From: R-help On Behalf Of > koller at science.iwi.ac.at > Sent: Wednesday, July 30, 2025 2:32 PM > To: r-help at r-project.org > Subject: [R] Problem with function gp in package cccp > > Dear all! > > I tried to solve a simple test example of a geometric program: > minimize x + y s.t. xy = 1 > The solution should be (1, 1). > > I tried: > F0 <- diag(2) # [m * n] m = number of terms of the > posynomial, n = number of variables > g0 <- log(matrix(1,2,1)) # [m * 1] > A <- matrix(c(1,1), 1, 2) # one constraint, one row > b <- log(matrix(1,1,1)) > RES <- gp(F0, g0, A=A, b=b) > > Though I received the correct solution, the function gives a warning: > In gp(F0, g0, A = A, b = b) : No restrictions provided, trying solve(). > > Also, when I try > RES <- gp(F0, g0, A="A", b=b) > or > gp(F0, g0) > > receiving the same result, I find out, that my equality constraints are > not > considered at all. > > In my view, the unconstraint problem should have (0, 0) as a solution, > btw. > > Am I missing something fundamental? > > Thanks in advance! > > Wolfgang > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From re|chm@nj @end|ng |rom @bcg|ob@|@net Fri Aug 1 22:53:35 2025 From: re|chm@nj @end|ng |rom @bcg|ob@|@net (Jeff Reichman) Date: Fri, 1 Aug 2025 15:53:35 -0500 Subject: [R] Problem with function gp in package cccp In-Reply-To: <1bec980f2452a04395dead6a26db1286@science.iwi.ac.at> References: <00c901dc028a$86916450$93b42cf0$@sbcglobal.net> <1bec980f2452a04395dead6a26db1286@science.iwi.ac.at> Message-ID: <004601dc0326$59974a40$0cc5dec0$@sbcglobal.net> So its that gp() wouldn't even activate equality constraints unless it also saw inequality ones. Interesting -----Original Message----- From: R-help On Behalf Of koller at science.iwi.ac.at Sent: Friday, August 1, 2025 10:40 AM To: r-help at r-project.org Subject: Re: [R] Problem with function gp in package cccp Thank you, Jeff and Bert! 1. As to the unconstrained problem I gave (which is not my main concern) I should have added that in geometric programming it is assumed that the target variables are positive, thus x,y > 0. This would also rule out my given solution, (0, 0), of the unconstrained problem. The positivity constraint in geometric programming is a consequence of the role the logarithmic transformation plays in the theory of geometric programming. 2. However, my concern is to find out how to define equality constraints and submit them as an argument to gp(), so I wanted to try out the most simple case. But it seems as gp() implicitely assumes there must be at least inequality constraints. If I add inequality constraints, then my equality constraints are not ignored by gp(). So, in the following example, I added a non-binding inequality constraint, and I receive the correct solution, this time for the correct reasons: ## Minimise P + Q subject to P*Q = 1 and 0.5*P^(-1)*Q^(-1) <= 1 F0 <- diag(2) # [m0 * n] m0 = number of terms of the posynomial, n = number of variables g0 <- log(matrix(1,2,1)) # [m0 * 1] bexp <- 1 A <- matrix(c(1,1), 1, 2) # one constraint, one row b <- log(matrix(bexp, 1, 1)) F1 <- matrix(c(-1,-1), 1, 2) # additional (redundant) inequality constraint [m1 * n] m1 = number of terms of the posynomial g1 <- log(matrix(0.5*bexp, 1, 1)) # [m1 * 1] RES <- gp(F0, g0, FList=list(F1), gList=list(g1), A=A, b=b) sol <- RES$pdv$x c(sol) # [1] 1 1 RES <- gp(F0, g0, FList=list(F1), gList=list(g1)) # without the equality constraint sol <- RES$pdv$x c(sol) # [1] 0.7071069 0.7071069 Best regards, Wolfgang Am 2025-08-01 04:18, schrieb Jeff Reichman: > In gp(F0, g0, A = A, b = b) : No restrictions provided, trying solve() > > > This likely means that while you've specified A and b, the solver > doesn't recognize any inequality (<=) or equality (=) restrictions - > because in the context of the gp() function from the CVXR or similar > geometric programming libraries in R, you're expected to provide > explicit inequality/equality markers or properly formatted constraint > matrices. > > So what's missing? Probably an argument like ineq = ... or eq = ... to > declare the type of constraint. > > Here's how to express your constraint properly, assuming the library > expects inequalities or equalities to be marked explicitly: > > # Properly declare equality constraints gp(F0, g0, eq=A, eq.b=b) > > Or possibly (depending on the package): > > gp(F0, g0, Aeq=A, beq=b) > > If the solver expects inequality constraints: > > gp(F0, g0, A=A, b=b, meq=1) # Indicating 1 equality constraint > > Jeff Reichman > > > -----Original Message----- > From: R-help On Behalf Of > koller at science.iwi.ac.at > Sent: Wednesday, July 30, 2025 2:32 PM > To: r-help at r-project.org > Subject: [R] Problem with function gp in package cccp > > Dear all! > > I tried to solve a simple test example of a geometric program: > minimize x + y s.t. xy = 1 > The solution should be (1, 1). > > I tried: > F0 <- diag(2) # [m * n] m = number of terms of the > posynomial, n = number of variables > g0 <- log(matrix(1,2,1)) # [m * 1] > A <- matrix(c(1,1), 1, 2) # one constraint, one row > b <- log(matrix(1,1,1)) > RES <- gp(F0, g0, A=A, b=b) > > Though I received the correct solution, the function gives a warning: > In gp(F0, g0, A = A, b = b) : No restrictions provided, trying solve(). > > Also, when I try > RES <- gp(F0, g0, A="A", b=b) > or > gp(F0, g0) > > receiving the same result, I find out, that my equality constraints > are not considered at all. > > In my view, the unconstraint problem should have (0, 0) as a solution, > btw. > > Am I missing something fundamental? > > Thanks in advance! > > Wolfgang > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. From p@u| @end|ng |rom @t@t@@uck|@nd@@c@nz Sun Aug 3 23:00:44 2025 From: p@u| @end|ng |rom @t@t@@uck|@nd@@c@nz (Paul Murrell) Date: Mon, 4 Aug 2025 09:00:44 +1200 Subject: [R] ggplot with arrows In-Reply-To: <6d6113c1-caa8-4792-b98c-02d451b31e0f@sapo.pt> References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> <6d6113c1-caa8-4792-b98c-02d451b31e0f@sapo.pt> Message-ID: <58cd08de-71fd-427d-ae02-7be2c8aca693@stat.auckland.ac.nz> Hi At the risk of being labelled a "purist", you do not have to leave R to gain access to the underlying components and modify them. The following code combines Rui's tidy up of the ggplot() call with an example of directly modifying the underlying 'grid' grob to add arrows to the ends. There are more arguments in arrow() that you can explore if you want to. library(ggplot2) library(grid) ggplot() + stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25, xlim = c(-5, 5) ) + theme_linedraw() grid.force() ## Check the name of the line grob ## grid.ls() grid.edit("GRID.polyline", grep=TRUE, arrow=arrow(ends="both")) Hope that helps. Paul On 2/08/2025 3:24 am, Rui Barradas wrote: > On 8/1/2025 4:15 PM, Rui Barradas wrote: >> On 8/1/2025 3:43 PM, Ebert,Timothy Aaron wrote: >>> I would save the graph as a PowerPoint object and then edit it in >>> PowerPoint. >>> library(ggplot2) >>> library(grid) >>> library(officer) >>> library(rvg) >>> x <- seq(-5, 5, length.out = 100) >>> y <- x^2 >>> data <- data.frame(x, y) >>> plot <- ggplot(data, aes(x, y)) + >>> ?? geom_path(color = "blue", linewidth = 1.25) + >>> ?? geom_segment( >>> ???? aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), >>> ???? arrow = arrow(angle = 20, type = "closed", ends = "both", length >>> = unit(0.2, "inches")), >>> ???? color = "red" >>> ?? ) + >>> ?? theme_linedraw() >>> doc <- read_pptx() >>> doc <- add_slide(doc, layout = "Title and Content", master = "Office >>> Theme") >>> doc <- ph_with(doc, dml(ggobj = plot), location = >>> ph_location_fullsize()) >>> print(doc, target = "quadratic_with_arrows.pptx") >>> >>> If I remember I think you have to ungroup it in PowerPoint and then >>> all elements become editable. The general approach can be done with >>> other file formats/programs, not just PowerPoint. >>> Tim >>> >>> -----Original Message----- >>> From: R-help On Behalf Of Thomas Subia >>> via R-help >>> Sent: Friday, August 1, 2025 10:31 AM >>> To: r-help at r-project.org >>> Subject: [R] ggplot with arrows >>> >>> [External Email] >>> >>> Consider: >>> >>> x <- seq(-5,5,length.out = 100) >>> y <- x^2 >>> data <- data.frame(x,y) >>> library(ggplot2) >>> ggplot(data,aes(x,y))+ >>> ?? stat_function( >>> ???? fun = function(x) x^2, >>> ???? color = "blue", linewidth = 1.25 >>> ?? ) + >>> ?? theme_linedraw() >>> I'd like to add an arrow to the ends of curve to illustrate the curve >>> continues indefinitely in that direction, ChatGPT suggests using >>> geom_segment or geom_link but there has an easier way to do this. >>> >>> Any suggestions would be appreciated. >>> >>> >>> ???????? [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide https://www.r-project.org/posting- >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide https://www.R-project.org/posting- >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> Hello, >> >> First of all, according to the documentation ?stat_function, section >> Arguments, >> >> >> data >> Ignored by stat_function(), do not use. >> >> >> As for the arrows, first get the equations of the lines tangent to the >> end points of the parabola, >> >> y = -10*x - 25 >> y = 10*x - 25 >> >> then compute segments' end points and plot. >> >> >> f <- function(x, b = -25, m) m*x + b >> arrow_data <- data.frame( >> ?? id = c("n", "p"), >> ?? x = c(-5, 5), >> ?? y = f(c(-5, 5), m = c(-10, 10)), >> ?? xend = c(-6, 6), >> ?? yend = f(c(-6, 6), m = c(-10, 10)) >> ) >> >> ggplot() + >> ?? stat_function( >> ???? fun = function(x) x^2, >> ???? color = "blue", linewidth = 1.25, >> ???? xlim = c(-5, 5) >> ?? ) + >> ?? geom_segment( >> ???? data = arrow_data, >> ???? mapping = aes(x = x, y = y, xend = xend, yend = yend, group = id), >> ???? arrow = arrow(length = unit(0.5, "cm")), >> ???? linewidth = 1.25, >> ???? linetype = "dashed", >> ???? inherit.aes = FALSE >> ?? ) + >> ?? theme_linedraw() >> >> >> >> Remove linetype and add color if you want. >> >> Hope this helps, >> >> Rui Barradas >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide https://www.R-project.org/posting- >> guide.html >> and provide commented, minimal, self-contained, reproducible code. > Hello, > > Sorry, my previous code is a bit messy. > > You don't need to group, so I removed 'id' from the arrow_data. > It's better to define the arrows' end points x coordinates as variables, > it makes it easier to change the plot at will. > > And the function is now defined with the intercept as last argument. > > f <- function(x, m, b = -25) m*x + b > > # here plot with linetype = "dashed" > x0 <- c(-5, 5) > x1 <- c(-6, 6) > arrow_data <- data.frame( > ? x = x0, > ? y = f(x = x0, m = c(-10, 10)), > ? xend = x1, > ? yend = f(x = x1, m = c(-10, 10)) > ) > > ggplot() + > ? stat_function( > ??? fun = function(x) x^2, > ??? color = "blue", linewidth = 1.25, > ??? xlim = c(-5, 5) > ? ) + > ? geom_segment( > ??? data = arrow_data, > ??? mapping = aes(x = x, y = y, xend = xend, yend = yend), > ??? arrow = arrow(length = unit(0.5, "cm")), > ??? linewidth = 1.25, > ??? linetype = "dashed", > ??? inherit.aes = FALSE > ? ) + > ? theme_linedraw() > > > #--- > > # here the line type is the default solid, so > # start the arrows a bit away from the parabola, 0.1 away. > x0 <- c(-5.1, 5.1) > x1 <- c(-6, 6) > arrow_data <- data.frame( > ? x = x0, > ? y = f(x = x0, m = c(-10, 10)), > ? xend = x1, > ? yend = f(x = x1, m = c(-10, 10)) > ) > > ggplot() + > ? stat_function( > ??? fun = function(x) x^2, > ??? color = "blue", linewidth = 1.25, > ??? xlim = c(-5, 5) > ? ) + > ? geom_segment( > ??? data = arrow_data, > ??? mapping = aes(x = x, y = y, xend = xend, yend = yend), > ??? arrow = arrow(length = unit(0.5, "cm")), > ??? linewidth = 1.25, > ??? inherit.aes = FALSE > ? ) + > ? theme_linedraw() > > > Hope this helps, > > Rui Barradas > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell (he/him) Te Kura Tatauranga | Department of Statistics Waipapa Taumata Rau | The University of Auckland Private Bag 92019, Auckland 1142, New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz www.stat.auckland.ac.nz/~paul/ From tebert @end|ng |rom u||@edu Mon Aug 4 01:37:35 2025 From: tebert @end|ng |rom u||@edu (Ebert,Timothy Aaron) Date: Sun, 3 Aug 2025 23:37:35 +0000 Subject: [R] ggplot with arrows In-Reply-To: <58cd08de-71fd-427d-ae02-7be2c8aca693@stat.auckland.ac.nz> References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> <6d6113c1-caa8-4792-b98c-02d451b31e0f@sapo.pt> <58cd08de-71fd-427d-ae02-7be2c8aca693@stat.auckland.ac.nz> Message-ID: That was good in that the arrows look like part of the figure. In this problem I have two choices. The easy one is that this is a one-off task. The easy solution (for me) is to to offload the figure to another program and add the arrows manually. They will look like I want and I will be done in 5 to 10 minutes. It might take a few minutes longer if I find that PowerPoint is not quite working out and I need a program like Photoshop. I can copy-paste, or change the output file type. The difficult problem is where this is one case in a broader application where I need to graph a function within the specified range and add arrows to the ends of the function if it continues beyond the plotted limits as expected from the plotted portion. If this is for a classroom it may use methods far beyond the abilities of the students present (programming, and mathematically). Arrows for sin(x) or tan(x) do not make as much sense as for the x^2 function provided. The program does not catch cases where the function may be undefined or change directions outside the printed range. The arrow gives the impression that the figure will continue in the same direction for all x outside of the printed range. Calculus gives us a way to check function performance. Something like this, though I suspect this is a start rather than a final solution: library(ggplot2) library(grid) library(numDeriv) Min_x <- -10 Max_x <- 1 my_function <- "x^2 / (1 - x)" f_expr <- parse(text = my_function) f <- function(x) eval(f_expr[[1]], envir = list(x = x)) detect_discontinuity <- function(f, Min_x, Max_x, buffer = 2, n = 1000, jump_tol = 100) { x_seq <- seq(Min_x - buffer, Max_x + buffer, length.out = n) y_seq <- tryCatch(f(x_seq), error = function(e) rep(NA, length(x_seq))) bad_vals <- !is.finite(y_seq) jumps <- abs(diff(y_seq)) big_jump <- which(jumps > jump_tol) discont_locs <- sort(unique(c( x_seq[bad_vals], x_seq[big_jump] ))) list( discontinuities = discont_locs, has_left = any(discont_locs < Min_x), has_right = any(discont_locs > Max_x) ) } plot_with_discontinuity_check <- function(f, Min_x, Max_x) { check <- detect_discontinuity(f, Min_x, Max_x) p <- ggplot() + stat_function( fun = f, color = "blue", linewidth = 1.25, xlim = c(Min_x, Max_x) ) + theme_linedraw() print(p) grid.force() if (!check$has_left && !check$has_right) { grid.edit("GRID.polyline", grep = TRUE, arrow = arrow(ends = "both")) } else if (!check$has_left) { grid.edit("GRID.polyline", grep = TRUE, arrow = arrow(ends = "first")) } else if (!check$has_right) { grid.edit("GRID.polyline", grep = TRUE, arrow = arrow(ends = "last")) } if (check$has_left) { grid.text("Left: Discontinuity prevents extension", x = unit(0.05, "npc"), y = unit(0.95, "npc"), just = "left", gp = gpar(col = "black", fontsize = 8)) } if (check$has_right) { grid.text("Right: Discontinuity prevents extension", x = unit(0.95, "npc"), y = unit(0.95, "npc"), just = "right", gp = gpar(col = "black", fontsize = 8)) } } plot_with_discontinuity_check(f, Min_x, Max_x) I suspect there are better approaches, but some form of error checking is essential to ensure that arrows are appropriate at both ends of the function as graphed. Graphs should not lie, but that is a difficult task in the generic problem. Prove that the function does not change direction or have a discontinuity outside the printed range from -infinity to +infinity. It is also possible that the graph is well behaved on one side but not the other. Is there a better solution? Are there other ways to check for conditions that might make arrows inappropriate? One could check and see if the graph ends at a discontinuity and add a bar at the end of the line. One might check to see if a discontinuity occurs within the figure and add a bar at the end of each line at the point of the discontinuity. I think the current graph glosses over the problem. How broadly does one define a function? Is this a function with respect to this problem: Ifelse(x>4,x^2,3x*x^0.5)? Tim -----Original Message----- From: Paul Murrell Sent: Sunday, August 3, 2025 5:01 PM To: Rui Barradas ; Ebert,Timothy Aaron ; Thomas Subia ; r-help at r-project.org Subject: Re: [R] ggplot with arrows [External Email] Hi At the risk of being labelled a "purist", you do not have to leave R to gain access to the underlying components and modify them. The following code combines Rui's tidy up of the ggplot() call with an example of directly modifying the underlying 'grid' grob to add arrows to the ends. There are more arguments in arrow() that you can explore if you want to. library(ggplot2) library(grid) ggplot() + stat_function( fun = function(x) x^2, color = "blue", linewidth = 1.25, xlim = c(-5, 5) ) + theme_linedraw() grid.force() ## Check the name of the line grob ## grid.ls() grid.edit("GRID.polyline", grep=TRUE, arrow=arrow(ends="both")) Hope that helps. Paul On 2/08/2025 3:24 am, Rui Barradas wrote: > On 8/1/2025 4:15 PM, Rui Barradas wrote: >> On 8/1/2025 3:43 PM, Ebert,Timothy Aaron wrote: >>> I would save the graph as a PowerPoint object and then edit it in >>> PowerPoint. >>> library(ggplot2) >>> library(grid) >>> library(officer) >>> library(rvg) >>> x <- seq(-5, 5, length.out = 100) >>> y <- x^2 >>> data <- data.frame(x, y) >>> plot <- ggplot(data, aes(x, y)) + >>> geom_path(color = "blue", linewidth = 1.25) + >>> geom_segment( >>> aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), >>> arrow = arrow(angle = 20, type = "closed", ends = "both", >>> length = unit(0.2, "inches")), >>> color = "red" >>> ) + >>> theme_linedraw() >>> doc <- read_pptx() >>> doc <- add_slide(doc, layout = "Title and Content", master = "Office >>> Theme") >>> doc <- ph_with(doc, dml(ggobj = plot), location = >>> ph_location_fullsize()) >>> print(doc, target = "quadratic_with_arrows.pptx") >>> >>> If I remember I think you have to ungroup it in PowerPoint and then >>> all elements become editable. The general approach can be done with >>> other file formats/programs, not just PowerPoint. >>> Tim >>> >>> -----Original Message----- >>> From: R-help On Behalf Of Thomas >>> Subia via R-help >>> Sent: Friday, August 1, 2025 10:31 AM >>> To: r-help at r-project.org >>> Subject: [R] ggplot with arrows >>> >>> [External Email] >>> >>> Consider: >>> >>> x <- seq(-5,5,length.out = 100) >>> y <- x^2 >>> data <- data.frame(x,y) >>> library(ggplot2) >>> ggplot(data,aes(x,y))+ >>> stat_function( >>> fun = function(x) x^2, >>> color = "blue", linewidth = 1.25 >>> ) + >>> theme_linedraw() >>> I'd like to add an arrow to the ends of curve to illustrate the >>> curve continues indefinitely in that direction, ChatGPT suggests >>> using geom_segment or geom_link but there has an easier way to do this. >>> >>> Any suggestions would be appreciated. >>> >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://st/ >>> at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl >>> .edu%7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a6233 >>> 1e1b84%7C0%7C0%7C638898516666803962%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0 >>> eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIs >>> IldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=D%2FYdiTEKELZpAQrNx6swSm%2BbuIG% >>> 2Bwln6aNImfl3ogl8%3D&reserved=0 PLEASE do read the posting guide >>> https://ww/ >>> w.r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d5151 >>> 875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0 >>> %7C638898516666831414%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydW >>> UsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D% >>> 3D%7C0%7C%7C%7C&sdata=CJpx9Ctsp3f1M85qYi95ZAUW2eTV7O7I9yBVeFLOK74%3D >>> &reserved=0 >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://st/ >>> at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl >>> .edu%7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a6233 >>> 1e1b84%7C0%7C0%7C638898516666843559%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0 >>> eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIs >>> IldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hpbeujBEoZL6iT4nktp5AlT59OX9ipn5 >>> e4zZOXOzo9U%3D&reserved=0 PLEASE do read the posting guide >>> https://ww/ >>> w.r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d5151 >>> 875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0 >>> %7C638898516666854776%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydW >>> UsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D% >>> 3D%7C0%7C%7C%7C&sdata=UAHkZfEudzeqGLHXuSsBVc%2FcWi9LXH5iU2vesxwPK7c% >>> 3D&reserved=0 >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> Hello, >> >> First of all, according to the documentation ?stat_function, section >> Arguments, >> >> >> data >> Ignored by stat_function(), do not use. >> >> >> As for the arrows, first get the equations of the lines tangent to >> the end points of the parabola, >> >> y = -10*x - 25 >> y = 10*x - 25 >> >> then compute segments' end points and plot. >> >> >> f <- function(x, b = -25, m) m*x + b >> arrow_data <- data.frame( >> id = c("n", "p"), >> x = c(-5, 5), >> y = f(c(-5, 5), m = c(-10, 10)), >> xend = c(-6, 6), >> yend = f(c(-6, 6), m = c(-10, 10)) >> ) >> >> ggplot() + >> stat_function( >> fun = function(x) x^2, >> color = "blue", linewidth = 1.25, >> xlim = c(-5, 5) >> ) + >> geom_segment( >> data = arrow_data, >> mapping = aes(x = x, y = y, xend = xend, yend = yend, group = id), >> arrow = arrow(length = unit(0.5, "cm")), >> linewidth = 1.25, >> linetype = "dashed", >> inherit.aes = FALSE >> ) + >> theme_linedraw() >> >> >> >> Remove linetype and add color if you want. >> >> Hope this helps, >> >> Rui Barradas >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://sta/ >> t.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl.e >> du%7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1 >> b84%7C0%7C0%7C638898516666865879%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1h >> cGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUI >> joyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2FHg3hccAA2VzI9ewCTjVd3DHf91CdJff92h5 >> AJrufMs%3D&reserved=0 PLEASE do read the posting guide >> https://www/ >> .r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d515187 >> 5104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C >> 638898516666877207%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIl >> YiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C >> 0%7C%7C%7C&sdata=zvwHm2iCBTPAPuwELSupCDmCZ3Mcq%2BpYz%2Fr7SuMyZT4%3D&r >> eserved=0 >> guide.html >> and provide commented, minimal, self-contained, reproducible code. > Hello, > > Sorry, my previous code is a bit messy. > > You don't need to group, so I removed 'id' from the arrow_data. > It's better to define the arrows' end points x coordinates as > variables, it makes it easier to change the plot at will. > > And the function is now defined with the intercept as last argument. > > f <- function(x, m, b = -25) m*x + b > > # here plot with linetype = "dashed" > x0 <- c(-5, 5) > x1 <- c(-6, 6) > arrow_data <- data.frame( > x = x0, > y = f(x = x0, m = c(-10, 10)), > xend = x1, > yend = f(x = x1, m = c(-10, 10)) > ) > > ggplot() + > stat_function( > fun = function(x) x^2, > color = "blue", linewidth = 1.25, > xlim = c(-5, 5) > ) + > geom_segment( > data = arrow_data, > mapping = aes(x = x, y = y, xend = xend, yend = yend), > arrow = arrow(length = unit(0.5, "cm")), > linewidth = 1.25, > linetype = "dashed", > inherit.aes = FALSE > ) + > theme_linedraw() > > > #--- > > # here the line type is the default solid, so # start the arrows a bit > away from the parabola, 0.1 away. > x0 <- c(-5.1, 5.1) > x1 <- c(-6, 6) > arrow_data <- data.frame( > x = x0, > y = f(x = x0, m = c(-10, 10)), > xend = x1, > yend = f(x = x1, m = c(-10, 10)) > ) > > ggplot() + > stat_function( > fun = function(x) x^2, > color = "blue", linewidth = 1.25, > xlim = c(-5, 5) > ) + > geom_segment( > data = arrow_data, > mapping = aes(x = x, y = y, xend = xend, yend = yend), > arrow = arrow(length = unit(0.5, "cm")), > linewidth = 1.25, > inherit.aes = FALSE > ) + > theme_linedraw() > > > Hope this helps, > > Rui Barradas > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat/ > .ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl.edu > %7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84 > %7C0%7C0%7C638898516666888977%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGki > OnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ > %3D%3D%7C0%7C%7C%7C&sdata=yCA5NQav4WOgUjjI9SifFdGomE0Ze%2BJhfd9q18gI%2 > BAQ%3D&reserved=0 PLEASE do read the posting guide > https://www/. > r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d51518751 > 04acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638 > 898516666900339%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOi > IwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C% > 7C%7C&sdata=8%2FhroJSwSWtqnRmI1CboaEeOnubjG%2FVUpBAM4kU9%2B54%3D&reser > ved=0 > guide.html > and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell (he/him) Te Kura Tatauranga | Department of Statistics Waipapa Taumata Rau | The University of Auckland Private Bag 92019, Auckland 1142, New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ From tg@77m @end|ng |rom y@hoo@com Mon Aug 4 02:00:23 2025 From: tg@77m @end|ng |rom y@hoo@com (Thomas Subia) Date: Mon, 4 Aug 2025 00:00:23 +0000 (UTC) Subject: [R] ggplot with arrows In-Reply-To: References: <1901631158.894125.1754058637556.ref@mail.yahoo.com> <1901631158.894125.1754058637556@mail.yahoo.com> <6d6113c1-caa8-4792-b98c-02d451b31e0f@sapo.pt> <58cd08de-71fd-427d-ae02-7be2c8aca693@stat.auckland.ac.nz> Message-ID: <1778328477.1487164.1754265623137@mail.yahoo.com> Thanks all for the suggestions!? Your suggestions will help my students better visualize how functions behave. and help me to write more efficient ggplot scripts! On Sunday, August 3, 2025 at 04:37:40 PM PDT, Ebert,Timothy Aaron wrote: That was good in that the arrows look like part of the figure. In this problem I have two choices. The easy one is that this is a one-off task. The easy solution (for me) is to to offload the figure to another program and add the arrows manually. They will look like I want and I will be done in 5 to 10 minutes. It might take a few minutes longer if I find that PowerPoint is not quite working out and I need a program like Photoshop. I can copy-paste, or change the output file type. The difficult problem is where this is one case in a broader application where I need to graph a function within the specified range and add arrows to the ends of the function if it continues beyond the plotted limits as expected from the plotted portion. If this is for a classroom it may use methods far beyond the abilities of the students present (programming, and mathematically). Arrows for sin(x) or tan(x) do not make as much sense as for the x^2 function provided. The program does not catch cases where the function may be undefined or change directions outside the printed range. The arrow gives the impression that the figure will continue in the same direction for all x outside of the printed range. Calculus gives us a way to check function performance. Something like this, though I suspect this is a start rather than a final solution: library(ggplot2) library(grid) library(numDeriv) Min_x <- -10 Max_x <- 1 my_function <- "x^2 / (1 - x)" f_expr <- parse(text = my_function) f <- function(x) eval(f_expr[[1]], envir = list(x = x)) detect_discontinuity <- function(f, Min_x, Max_x, buffer = 2, n = 1000, jump_tol = 100) { ? x_seq <- seq(Min_x - buffer, Max_x + buffer, length.out = n) ? y_seq <- tryCatch(f(x_seq), error = function(e) rep(NA, length(x_seq))) ? bad_vals <- !is.finite(y_seq) ? jumps <- abs(diff(y_seq)) ? big_jump <- which(jumps > jump_tol) ? discont_locs <- sort(unique(c( ? ? x_seq[bad_vals], ? ? x_seq[big_jump] ? ))) ? list( ? ? discontinuities = discont_locs, ? ? has_left = any(discont_locs < Min_x), ? ? has_right = any(discont_locs > Max_x) ? ) } plot_with_discontinuity_check <- function(f, Min_x, Max_x) { ? check <- detect_discontinuity(f, Min_x, Max_x) ? p <- ggplot() + ? ? stat_function( ? ? ? fun = f, ? ? ? color = "blue", linewidth = 1.25, ? ? ? xlim = c(Min_x, Max_x) ? ? ) + ? ? theme_linedraw() ? print(p) ? grid.force() ? if (!check$has_left && !check$has_right) { ? ? grid.edit("GRID.polyline", grep = TRUE, arrow = arrow(ends = "both")) ? } else if (!check$has_left) { ? ? grid.edit("GRID.polyline", grep = TRUE, arrow = arrow(ends = "first")) ? } else if (!check$has_right) { ? ? grid.edit("GRID.polyline", grep = TRUE, arrow = arrow(ends = "last")) ? } ? if (check$has_left) { ? ? grid.text("Left: Discontinuity prevents extension", ? ? ? ? ? ? ? x = unit(0.05, "npc"), y = unit(0.95, "npc"), ? ? ? ? ? ? ? just = "left", gp = gpar(col = "black", fontsize = 8)) ? } ? if (check$has_right) { ? ? grid.text("Right: Discontinuity prevents extension", ? ? ? ? ? ? ? x = unit(0.95, "npc"), y = unit(0.95, "npc"), ? ? ? ? ? ? ? just = "right", gp = gpar(col = "black", fontsize = 8)) ? } } plot_with_discontinuity_check(f, Min_x, Max_x) I suspect there are better approaches, but some form of error checking is essential to ensure that arrows are appropriate at both ends of the function as graphed. Graphs should not lie, but that is a difficult task in the generic problem. Prove that the function does not change direction or have a discontinuity outside the printed range from -infinity to +infinity. It is also possible that the graph is well behaved on one side but not the other. Is there a better solution? Are there other ways to check for conditions that might make arrows inappropriate? One could check and see if the graph ends at a discontinuity and add a bar at the end of the line. One might check to see if a discontinuity occurs within the figure and add a bar at the end of each line at the point of the discontinuity. I think the current graph glosses over the problem. How broadly does one define a function? Is this a function with respect to this problem: Ifelse(x>4,x^2,3x*x^0.5)? Tim -----Original Message----- From: Paul Murrell Sent: Sunday, August 3, 2025 5:01 PM To: Rui Barradas ; Ebert,Timothy Aaron ; Thomas Subia ; r-help at r-project.org Subject: Re: [R] ggplot with arrows [External Email] Hi At the risk of being labelled a "purist", you do not have to leave R to gain access to the underlying components and modify them. The following code combines Rui's tidy up of the ggplot() call with an example of directly modifying the underlying 'grid' grob to add arrows to the ends.? There are more arguments in arrow() that you can explore if you want to. library(ggplot2) library(grid) ggplot() + ? stat_function( ? ? fun = function(x) x^2, ? ? color = "blue", linewidth = 1.25, ? ? xlim = c(-5, 5) ? ) + ? theme_linedraw() grid.force() ## Check the name of the line grob ## grid.ls() grid.edit("GRID.polyline", grep=TRUE, ? ? ? ? ? arrow=arrow(ends="both")) Hope that helps. Paul On 2/08/2025 3:24 am, Rui Barradas wrote: > On 8/1/2025 4:15 PM, Rui Barradas wrote: >> On 8/1/2025 3:43 PM, Ebert,Timothy Aaron wrote: >>> I would save the graph as a PowerPoint object and then edit it in >>> PowerPoint. >>> library(ggplot2) >>> library(grid) >>> library(officer) >>> library(rvg) >>> x <- seq(-5, 5, length.out = 100) >>> y <- x^2 >>> data <- data.frame(x, y) >>> plot <- ggplot(data, aes(x, y)) + >>>? ? geom_path(color = "blue", linewidth = 1.25) + >>>? ? geom_segment( >>>? ? ? aes(x = x[1], y = y[1], xend = x[100], yend = y[100]), >>>? ? ? arrow = arrow(angle = 20, type = "closed", ends = "both", >>> length = unit(0.2, "inches")), >>>? ? ? color = "red" >>>? ? ) + >>>? ? theme_linedraw() >>> doc <- read_pptx() >>> doc <- add_slide(doc, layout = "Title and Content", master = "Office >>> Theme") >>> doc <- ph_with(doc, dml(ggobj = plot), location = >>> ph_location_fullsize()) >>> print(doc, target = "quadratic_with_arrows.pptx") >>> >>> If I remember I think you have to ungroup it in PowerPoint and then >>> all elements become editable. The general approach can be done with >>> other file formats/programs, not just PowerPoint. >>> Tim >>> >>> -----Original Message----- >>> From: R-help On Behalf Of Thomas >>> Subia via R-help >>> Sent: Friday, August 1, 2025 10:31 AM >>> To: r-help at r-project.org >>> Subject: [R] ggplot with arrows >>> >>> [External Email] >>> >>> Consider: >>> >>> x <- seq(-5,5,length.out = 100) >>> y <- x^2 >>> data <- data.frame(x,y) >>> library(ggplot2) >>> ggplot(data,aes(x,y))+ >>>? ? stat_function( >>>? ? ? fun = function(x) x^2, >>>? ? ? color = "blue", linewidth = 1.25 >>>? ? ) + >>>? ? theme_linedraw() >>> I'd like to add an arrow to the ends of curve to illustrate the >>> curve continues indefinitely in that direction, ChatGPT suggests >>> using geom_segment or geom_link but there has an easier way to do this. >>> >>> Any suggestions would be appreciated. >>> >>> >>>? ? ? ? ? [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://st/ >>> at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl >>> .edu%7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a6233 >>> 1e1b84%7C0%7C0%7C638898516666803962%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0 >>> eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIs >>> IldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=D%2FYdiTEKELZpAQrNx6swSm%2BbuIG% >>> 2Bwln6aNImfl3ogl8%3D&reserved=0 PLEASE do read the posting guide >>> https://ww/ >>> w.r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d5151 >>> 875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0 >>> %7C638898516666831414%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydW >>> UsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D% >>> 3D%7C0%7C%7C%7C&sdata=CJpx9Ctsp3f1M85qYi95ZAUW2eTV7O7I9yBVeFLOK74%3D >>> &reserved=0 >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://st/ >>> at.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl >>> .edu%7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a6233 >>> 1e1b84%7C0%7C0%7C638898516666843559%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0 >>> eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIs >>> IldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hpbeujBEoZL6iT4nktp5AlT59OX9ipn5 >>> e4zZOXOzo9U%3D&reserved=0 PLEASE do read the posting guide >>> https://ww/ >>> w.r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d5151 >>> 875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0 >>> %7C638898516666854776%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydW >>> UsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D% >>> 3D%7C0%7C%7C%7C&sdata=UAHkZfEudzeqGLHXuSsBVc%2FcWi9LXH5iU2vesxwPK7c% >>> 3D&reserved=0 >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> Hello, >> >> First of all, according to the documentation ?stat_function, section >> Arguments, >> >> >> data >> Ignored by stat_function(), do not use. >> >> >> As for the arrows, first get the equations of the lines tangent to >> the end points of the parabola, >> >> y = -10*x - 25 >> y = 10*x - 25 >> >> then compute segments' end points and plot. >> >> >> f <- function(x, b = -25, m) m*x + b >> arrow_data <- data.frame( >>? ? id = c("n", "p"), >>? ? x = c(-5, 5), >>? ? y = f(c(-5, 5), m = c(-10, 10)), >>? ? xend = c(-6, 6), >>? ? yend = f(c(-6, 6), m = c(-10, 10)) >> ) >> >> ggplot() + >>? ? stat_function( >>? ? ? fun = function(x) x^2, >>? ? ? color = "blue", linewidth = 1.25, >>? ? ? xlim = c(-5, 5) >>? ? ) + >>? ? geom_segment( >>? ? ? data = arrow_data, >>? ? ? mapping = aes(x = x, y = y, xend = xend, yend = yend, group = id), >>? ? ? arrow = arrow(length = unit(0.5, "cm")), >>? ? ? linewidth = 1.25, >>? ? ? linetype = "dashed", >>? ? ? inherit.aes = FALSE >>? ? ) + >>? ? theme_linedraw() >> >> >> >> Remove linetype and add color if you want. >> >> Hope this helps, >> >> Rui Barradas >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://sta/ >> t.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl.e >> du%7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1 >> b84%7C0%7C0%7C638898516666865879%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1h >> cGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUI >> joyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2FHg3hccAA2VzI9ewCTjVd3DHf91CdJff92h5 >> AJrufMs%3D&reserved=0 PLEASE do read the posting guide >> https://www/ >> .r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d515187 >> 5104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C >> 638898516666877207%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIl >> YiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C >> 0%7C%7C%7C&sdata=zvwHm2iCBTPAPuwELSupCDmCZ3Mcq%2BpYz%2Fr7SuMyZT4%3D&r >> eserved=0 >> guide.html >> and provide commented, minimal, self-contained, reproducible code. > Hello, > > Sorry, my previous code is a bit messy. > > You don't need to group, so I removed 'id' from the arrow_data. > It's better to define the arrows' end points x coordinates as > variables, it makes it easier to change the plot at will. > > And the function is now defined with the intercept as last argument. > > f <- function(x, m, b = -25) m*x + b > > # here plot with linetype = "dashed" > x0 <- c(-5, 5) > x1 <- c(-6, 6) > arrow_data <- data.frame( >? ? x = x0, >? ? y = f(x = x0, m = c(-10, 10)), >? ? xend = x1, >? ? yend = f(x = x1, m = c(-10, 10)) > ) > > ggplot() + >? ? stat_function( >? ? ? fun = function(x) x^2, >? ? ? color = "blue", linewidth = 1.25, >? ? ? xlim = c(-5, 5) >? ? ) + >? ? geom_segment( >? ? ? data = arrow_data, >? ? ? mapping = aes(x = x, y = y, xend = xend, yend = yend), >? ? ? arrow = arrow(length = unit(0.5, "cm")), >? ? ? linewidth = 1.25, >? ? ? linetype = "dashed", >? ? ? inherit.aes = FALSE >? ? ) + >? ? theme_linedraw() > > > #--- > > # here the line type is the default solid, so # start the arrows a bit > away from the parabola, 0.1 away. > x0 <- c(-5.1, 5.1) > x1 <- c(-6, 6) > arrow_data <- data.frame( >? ? x = x0, >? ? y = f(x = x0, m = c(-10, 10)), >? ? xend = x1, >? ? yend = f(x = x1, m = c(-10, 10)) > ) > > ggplot() + >? ? stat_function( >? ? ? fun = function(x) x^2, >? ? ? color = "blue", linewidth = 1.25, >? ? ? xlim = c(-5, 5) >? ? ) + >? ? geom_segment( >? ? ? data = arrow_data, >? ? ? mapping = aes(x = x, y = y, xend = xend, yend = yend), >? ? ? arrow = arrow(length = unit(0.5, "cm")), >? ? ? linewidth = 1.25, >? ? ? inherit.aes = FALSE >? ? ) + >? ? theme_linedraw() > > > Hope this helps, > > Rui Barradas > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat/ > .ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C02%7Ctebert%40ufl.edu > %7C08d5151875104acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84 > %7C0%7C0%7C638898516666888977%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGki > OnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ > %3D%3D%7C0%7C%7C%7C&sdata=yCA5NQav4WOgUjjI9SifFdGomE0Ze%2BJhfd9q18gI%2 > BAQ%3D&reserved=0 PLEASE do read the posting guide > https://www/. > r-project.org%2Fposting-&data=05%7C02%7Ctebert%40ufl.edu%7C08d51518751 > 04acc0a3208ddd2d0d5b2%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C638 > 898516666900339%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOi > IwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C% > 7C%7C&sdata=8%2FhroJSwSWtqnRmI1CboaEeOnubjG%2FVUpBAM4kU9%2B54%3D&reser > ved=0 > guide.html > and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell (he/him) Te Kura Tatauranga | Department of Statistics Waipapa Taumata Rau | The University of Auckland Private Bag 92019, Auckland 1142, New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ From 721mo@@d|k @end|ng |rom gm@||@com Mon Aug 4 19:29:05 2025 From: 721mo@@d|k @end|ng |rom gm@||@com (mo. sadik khan) Date: Mon, 4 Aug 2025 22:59:05 +0530 Subject: [R] Bug Report: R for Windows installer fails to enable Intel MKL on modern hardware Message-ID: Dear R Core Development Team, I am writing to report a potential issue with the standard R installer for Windows. On modern, high-performance hardware, the installer does not appear to be automatically enabling the Intel Math Kernel Library (MKL) as expected, defaulting instead to the standard, single-threaded BLAS/LAPACK libraries. Here are the details of my system and the steps to reproduce the issue: *1. System Information* - *Hardware:* Lenovo Legion Pro 5 Laptop - *Operating System:* Windows 11 x64 (build 26100) - *R Version:* R version 4.5.1 (2025-06-13 ucrt) - *sessionInfo() Output:* R version 4.5.1 (2025-06-13 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 26100) Matrix products: default LAPACK version 3.12.1 locale: [1] LC_COLLATE=English_United States.utf8 [2] LC_CTYPE=English_United States.utf8 [3] LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.utf8 *2. Steps to Reproduce* 1. Performed a clean uninstall of any previous R versions. 2. Downloaded the latest R installer from the official CRAN mirror: https://cran.r-project.org/bin/windows/base/. 3. Ran the installer using the standard, default settings. 4. Opened R and ran the sessionInfo() command to check the linked math libraries. *3. Expected Result* I expected the sessionInfo() output to show a reference to mkl_rt.dll in the LAPACK line, confirming that the high-performance, multi-threaded MKL was active. *4. Actual Result* The sessionInfo() output shows Matrix products: default and LAPACK version 3.12.1, with no mention of MKL. This indicates that the standard, slower libraries were installed. This significantly impacts performance for computationally intensive tasks like PCA on large matrices. Thank you for your incredible work on R. I hope this report is helpful in improving the installation experience on Windows. Please let me know if any further information or testing would be useful. Sincerely, [Your Name] [[alternative HTML version deleted]] From ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de Tue Aug 5 08:37:53 2025 From: ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de (Uwe Ligges) Date: Tue, 5 Aug 2025 08:37:53 +0200 Subject: [R] Bug Report: R for Windows installer fails to enable Intel MKL on modern hardware In-Reply-To: References: Message-ID: <9a45aee7-9b79-4142-bbf1-faddeee0c69f@statistik.tu-dortmund.de> On 04.08.2025 19:29, mo. sadik khan wrote: > Dear R Core Development Team, > > I am writing to report a potential issue with the standard R installer for > Windows. On modern, high-performance hardware, the installer does not > appear to be automatically enabling the Intel Math Kernel Library (MKL) as > expected, defaulting instead to the standard, single-threaded BLAS/LAPACK > libraries. Yes. Whch documentation tells you it would do so automatically? Best, Uwe Ligges > > Here are the details of my system and the steps to reproduce the issue: > > *1. System Information* > > - > > *Hardware:* Lenovo Legion Pro 5 Laptop > - > > *Operating System:* Windows 11 x64 (build 26100) > - > > *R Version:* R version 4.5.1 (2025-06-13 ucrt) > - > > *sessionInfo() Output:* > > R version 4.5.1 (2025-06-13 ucrt) > Platform: x86_64-w64-mingw32/x64 > Running under: Windows 11 x64 (build 26100) > > Matrix products: default > LAPACK version 3.12.1 > > locale: > [1] LC_COLLATE=English_United States.utf8 > [2] LC_CTYPE=English_United States.utf8 > [3] LC_MONETARY=English_United States.utf8 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.utf8 > > > *2. Steps to Reproduce* > > 1. > > Performed a clean uninstall of any previous R versions. > 2. > > Downloaded the latest R installer from the official CRAN mirror: > https://cran.r-project.org/bin/windows/base/. > 3. > > Ran the installer using the standard, default settings. > 4. > > Opened R and ran the sessionInfo() command to check the linked math > libraries. > > *3. Expected Result* I expected the sessionInfo() output to show a > reference to mkl_rt.dll in the LAPACK line, confirming that the > high-performance, multi-threaded MKL was active. > > *4. Actual Result* The sessionInfo() output shows Matrix products: default > and LAPACK version 3.12.1, with no mention of MKL. This indicates that the > standard, slower libraries were installed. This significantly impacts > performance for computationally intensive tasks like PCA on large matrices. > > Thank you for your incredible work on R. I hope this report is helpful in > improving the installation experience on Windows. Please let me know if any > further information or testing would be useful. > > Sincerely, > > [Your Name] > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. From pd@|gd @end|ng |rom gm@||@com Tue Aug 5 12:02:45 2025 From: pd@|gd @end|ng |rom gm@||@com (peter dalgaard) Date: Tue, 5 Aug 2025 12:02:45 +0200 Subject: [R] Drawing random numbers from Uniform distribution with infinite range In-Reply-To: References: Message-ID: Or rlogis(1e6, scale=.5) which is the same thing. But the logistic distribution is in no reasonable sense a uniform on the entire line, any more than the Gaussian is. (Some notion of a "random real" is involved in Benford's law of first digits, but that involves having a uniform distribution of log(X) and then increasing the range.) -pd > On 30 Jul 2025, at 14:11 , Richard O'Keefe wrote: > > Let's look at something that *would* work if it were not that IEEE > doubles are relatively small discrete set,. > > Suppose we had two things. > - a U(0,1) uniform random generator able to generate any *real* in the > range 0 .. 1 > - an implementation of atanh() that works for any real in the range 0 > .. 1 and can return any real number. > Then atanh(runif(n)*2 - 1) would do pretty much what you want,. > Try it in R. > f <- function (n = 1000000) atanh(runif(n)*2 - 1) > summary(f()) > It turns out that working with *representable* numbers means that the > results of f() are limited to > roughly -18,.4 to 18.4, and with n = 1000000 the extremes are almost > always around 7. > Something that, for actual real numbers, could return *any* real, for > representable numbers > can only return -18-and-a-bit to +18-and-a-bit. > > This suggests a completely different approach to your original > problem, whatever it is. > Instead of working with the entire real line, transform your problem > to work with the interval (0,1). > > On Tue, 29 Jul 2025 at 04:01, Daniel Lobo wrote: >> >> Hi, >> >> I want to draw a set of random number from Uniform distribution where >> Support is the entire Real line. >> >> runif(4, min = -Inf, max = Inf) >> >> However it produces all NAN >> >> Could you please help with the right approach? >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com