tidymodels / TMwR

Code and content for "Tidy Modeling with R"
https://tmwr.org
Other
604 stars 285 forks source link

Suggestion to improve code in TMwR where parallel processing is involved #320

Closed bhattmaulik closed 2 years ago

bhattmaulik commented 2 years ago

I was trying to knit the gitbook version of the book TMwR, but I was unable to. I am using a Windows system, and doMC package doesn't work on it. In the later chapters (like Chapter 15 of workflow-sets) there is a code so that it can work on both, Windows and non-Windows system. However, this code, which involves using grepl function and R.Version()$platform to decide whether this system has Windows or any other operating system, it was not working on my laptop. When I write in console R.Version()$platform, the output is "x86_64-w64-mingw32". So, I changed the code as follows:

cores <- parallel::detectCores()
if(Sys.info()['sysname']=="Windows"){
   library(doParallel)
   cl <- makePSOCKcluster(cores)
   registerDoParallel(cl)
}else {
   library(doMC)
   registerDoMC(cores = cores)
}

After this change, the code is working now.

juliasilge commented 2 years ago

Thank you so much for reading @bhattmaulik! 🙌 This is related to #201, and I'll share again what we said there:

The tune package itself works well on Windows (you can also read about parallel processing here) but I don't believe we will maintain the book in such a way that it can build on any OS. The code you see rendered online at tmwr.org is general and not OS-specific but the code we use to build the book/website does depend on which OS we are building with.

We are committed to the book having code you read that works on all OSes, but not to building the book in such a way that it can be automatically built on all OSes.

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.