Re: [R] R Code Execution taking forever

2022-04-23 Thread Jim Lemon
HI Paul,
I had a problem a bit like this when trying to implement the Lim-Wolfe
imputation for ranks. The size of the output matrix increases
exponentially with the size of the initial matrix and it goes into
disk-swapping slow motion. It works for small matrices, but rapidly
runs out of memory. I have planned to insert code to only retain the
largest maximum to fix this. If I get to it, I'll post the result.

Jim

On Sun, Apr 24, 2022 at 11:01 AM Paul Bernal  wrote:
>
> Dear R friends,
>
> Hope you are doing great. The reason why I am contacting you all, is
> because the code I am sharing with you takes forever. It started running at
> 2:00 AM today, and it's 7:52 PM and is still running (see code at the end
> of this mail).
>
> I am using Rx64  4.1.2, and the code is being executed in RStudio. The
> RStudio version I am currently using is Version 2022.02.0 Build 443
> "Prairie Trillium" Release (9f796939, 2022-02-16) for Windows.
>
> My PC specs:
> Processor: Intel(R) Core(TM) i5-10310U CPU @ 1.70 GHz
> Installed RAM: 16.0 GB (15.6 GB usable)
> System type: 64-bit operating system, x64-based processor
> Local Disc(C:) Free Space: 274 GB
>
> I am wondering if there is/are a set of system variable(s) or something I
> could do to improve the performance of the program.
>
> It is really odd this code has taken this much (and it is still running).
>
> Any help and/or guidance would be greatly appreciated.
>
> Best regards,
> Paul
>
>
>
>
> #performing 1,000,000 simulations 10 times
> num_trials_6 = 100
> dice_rolls_6 = num_trials_6*12
> num_dice_6 = 1
> dice_sides_6 = 6
>
> prob_frame_6 <- data.frame(matrix(ncol = 10, nrow = 1))
>
> k <- 0
> while(k < 10){
>   dice_simul_6 = data.frame(dice(rolls = dice_rolls_6, ndice = num_dice_6,
> sides = dice_sides_6, plot.it = FALSE))
>
>   #constructing matrix containing results of all dice rolls by month
>   prob_matrix_6 <- data.frame(matrix(dice_simul_6[,1], ncol = 12, byrow =
> TRUE))
>
>   #naming each column by it's corresponding month name
>   colnames(prob_matrix_6) <-
> c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
>
>
>   #assigning each personĀ“s name depending on the number showed in the dice
> once rolled
>   for (i in 1:nrow(prob_matrix_6)){
> for (j in 1:ncol(prob_matrix_6)){
>   if (prob_matrix_6[i,j] == 1){
> prob_matrix_6[i,j] = "Alice"
>   }
>   if (prob_matrix_6[i,j] == 2){
> prob_matrix_6[i,j] = "Bob"
>   }
>   if (prob_matrix_6[i,j] == 3){
> prob_matrix_6[i,j] = "Charlie"
>   }
>   if (prob_matrix_6[i,j] == 4){
> prob_matrix_6[i,j] = "Don"
>   }
>   if (prob_matrix_6[i,j] == 5){
> prob_matrix_6[i,j] = "Ellen"
>   }
>   if (prob_matrix_6[i,j] == 6){
> prob_matrix_6[i,j] = "Fred"
>   }
>
> }
>   }
>
>   #calculating column  which will have a 1 if trial was successful and a 0
> otherwise
>   prob_matrix_6['success'] <- for (i in 1:nrow(prob_matrix_6)){
> if (("Alice" %in% prob_matrix_6[i,]) & ("Bob" %in% prob_matrix_6[i,]) &
> ("Charlie" %in% prob_matrix_6[i,]) & ("Don" %in% prob_matrix_6[i,]) &
> ("Ellen" %in% prob_matrix_6[i,]) & ("Fred" %in% prob_matrix_6[i,])){
>   prob_matrix_6[i,13] = 1
> }else{
>   prob_matrix_6[i,13] = 0
> }
>   }
>
>   #relabeling column v13 so that its new name is success
>   colnames(prob_matrix_6)[13] <- "success"
>
>
>   #calculating probability of success
>
>   p6 = sum(prob_matrix_6$success)/nrow(prob_matrix_6)
>   prob_frame_6 <- cbind(prob_frame_6, p6)
>
>   k = k + 1
>
> }
>
> prob_frame_6 <- prob_frame_6[11:20]
> colnames(prob_frame_6) <-
> c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")
> average_prob_frame_6 <- rowMeans(prob_frame_6)
> trial_100_10_frame <- cbind(prob_frame_6, average_prob_frame_6)
> final_frame_6 <- trial_100_10_frame
> colnames(final_frame_6) <-
> c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10", "avg_prob_frame_5")
>
> write.csv(final_frame_6, "OneMillion_Trials_Ten_Times_Results.csv")
> print(final_frame_6)
> print(paste("The average probability of success when doing 1,000,000 trials
> 10 times is:", average_prob_frame_6))
>
> [[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] QGIS and R

2022-04-23 Thread Ivan Krylov
On Sat, 23 Apr 2022 15:32:07 +0100
Nick Wray  wrote:

> For example I have installed RQGIS successfully but any example
> programs won't run because (apparently)  I haven't got x-display
> enabled 

Bad news: RQGIS is apparently not maintained any more [1,2], because it
only supports the old version of QGIS (2 instead of 3). There was
something called RQGIS3, but it didn't work out, either [3]. Your best
bet might be something else called qgisprocess [4], which isn't on CRAN
(yet?), but at least doesn't have scary warnings in its README.

I'll second the advice to ask in R-SIG-Geo. That X11-related problem (?)
might solve itself by the time you switch to another package, but if it
doesn't, make sure to mention the exact error message and the operating
system you are running: X11 is very different between Windows, macOS
and other POSIX-compatible OSes.

>   [[alternative HTML version deleted]]

P.S. Please compose your messages to R mailing lists in plain text, not
HTML.

-- 
Best regards,
Ivan

[1] https://cran.r-project.org/package=RQGIS

[2] https://github.com/r-spatial/RQGIS

[3] https://github.com/r-spatial/RQGIS3

[4] https://github.com/paleolimbot/qgisprocess

__
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] QGIS and R

2022-04-23 Thread Bert Gunter
https://www.qgis.org/en/site/   (obviously)

Probably better to ask on  https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Sat, Apr 23, 2022 at 7:32 AM Nick Wray  wrote:
>
> For my PhD researches I am trying to get to grips with QGIS and in
> particular with using QGIS within R, but it's a steep and tricky learning
> curve.  For example I have installed RQGIS successfully but any example
> programs won't run because (apparently)  I haven't got x-display enabled -
> I haven't got the foggiest what that is or how to get it.  So basically my
> question is - can anyone recommend any sources/websites/books/videos etc
> which would give examples/walkthroughs/explanations of how to get off the
> ground with QGIS in R/RQGIS etc?  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.