Open pgensler opened 7 years ago
Yes. I did it on purpose. Take a look at the base container this depends on: tidyviz-base There's a install_github file. You'll find some useful snippets there. One of them is for timestamp log.
Hope this helps
It does, thanks. I was trying to modify your code so that I could see when a package started, and completed install, and this is what I have come up with:
I'm wondering if this is a good use case for the glue package to combine the strings package name, along with when execution is complete for a function?
if (!require("pacman")) install.packages("pacman","glue")
pacman::p_load(pathological)
if (!file.exists("~/.Rprofile"))
# only create if not already there
file.create("~/.Rprofile")
perfil <- pathological::r_profile()
cat(
.Last = function() {
cond = suppressWarnings(!require(fortunes, quietly=TRUE))
if(cond)
try(install.packages('fortunes'), silent=TRUE)
message('Package install completed for package',{x},'at',date(), '\n')
}
# aliases
s <- base::summary
h <- utils::head
n <- base::names
.First <- function(){
x <- library(fortunes)
glue::('Starting Install for package'{x})
}
, file = perfil, append=TRUE, sep = "\n")
I've noticed your call to install glue outside pacman call. Better this way:
if (!require("pacman")) install.packages("pacman")
pacman::p_load(pathological, glue)
Also, you don't need all the code for your purpose:
if (!file.exists("~/.Rprofile"))
# only create if not already there
file.create("~/.Rprofile")
myprofile <- pathological::r_profile()
cat(
.Last = function() {
cond = suppressWarnings(!require(fortunes, quietly=TRUE))
if(cond)
try(install.packages('fortunes'), silent=TRUE)
message('Package install completed for package',{x},'at',date(), '\n')
}
.First <- function(){
x <- library(fortunes)
glue::('Starting Install for package'{x})
}
, file = myprofile, append=TRUE, sep = "\n")
Hope this works
Hmm, I'm not exactly sure how glue works, as that last line was causing me errors, but this seems to work on startup:
.Last = function() {
cond = suppressWarnings(!require(fortunes, quietly=TRUE))
if(cond)
try(install.packages('fortunes'), silent=TRUE)
message('Package install completed for package',{x},'at',date(), '\n')
}
.First <- function(){
x <- library(fortunes)
message('Starting Install for package',{x})
}
which produces:
Starting Install for packagefortunesmethodsbase
But if I call install.packages("tidytext"), shouldn't I expect the .First and .last calls to trigger, or does that only trigger at the beginning of an R Session?
.First( ) will be run at the start of the R session and .Last( ) will be run at the end of the session.
@verajosemanuel so is it possible to have a .Last() call trigger after the install.packages completes, or is it better to simply create a wrapper for install.packages
, similar to pacman::p_install
If I understand your script, it seems like fortunes is simply a placeholder for your package, and when the function completes, it should output a message?
Fortunes is a package showing random sentences on console. My script shows message only for packages you add to the script itself. Otherwise if you need to show a message after installation of any package anytime you need to call a wrapper.
I understand what the fortunes package does, but isen't that a placeholder? Like these lines from your build file:
[0m [91m installing source* package ‘StanHeaders’ ... [0m [91m package ‘StanHeaders’ successfully unpacked and MD5 sums checked [0m [91m libs [0m [91mar: creating ../lib/libStanHeaders.a [0m [91minstalling via 'install.libs.R' to /usr/local/lib/R/site-library/StanHeaders [0m [91m inst [0m [91m help [0m [91m* installing help indices [0m [91m building package indices [0m [91m* testing if installed package can be loaded [0m [91m DONE (StanHeaders) [0m [91mGoodbye at Tue Oct 31 21:37:16 2017
How is stanheaders using the .First and .Last call if you diden't explicitly define install.packages(rstan)
? Aren't you kinda wrapping install.packages right at the installation process? Thanks for your help with this.
that is very odd, didn't notice this. I've to assume this behavior is due to some hidden call to .Last even if you don't make it explicit. I'll have to test it.
Thanks for reporting
@verajosemanuel No problem, it's just that I'd really like to create some sort of way of stating that the package install started for package x, and completed for package x. That would be incredibly helpful.
FYI it looks like devtools::install_cran
has this functionality, but you need to supply the packages as a character vector
Have you looked at pacman functions? maybe any is suitable for you. https://cran.r-project.org/web/packages/pacman/vignettes/Introduction_to_pacman.html
pacman does not support this natively, but I would love it if it did. You should try devtools::install_cran
to see if that outputs something cleaner for your build. Any particular reason why you are installing some packages from GitHub, and not just from source?
just because the time i've included in the dockerfile the only option was github, and had no time to check it all...
I see. It might be worth trying to do a simple unit test via testthat's tool to view what packages installed successfully: Nice output of what installed, and what did not. https://twitter.com/dvaughan32/likes
Hello,
I'm curious how you were able to implement time stamps in your Build logs for this container such as:
Did you purposefully intend to do so? I've been meaning to try and do something similar for a container I am working on. Thanks