Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamps of installed packages in container? #1

Open
pgensler opened this issue Oct 30, 2017 · 15 comments
Open

Timestamps of installed packages in container? #1

pgensler opened this issue Oct 30, 2017 · 15 comments

Comments

@pgensler
Copy link

pgensler commented Oct 30, 2017

Hello,

I'm curious how you were able to implement time stamps in your Build logs for this container such as:

�[91mGoodbye at Mon Oct 23 19:00:22 2017

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

@verajosemanuel
Copy link
Owner

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

@pgensler
Copy link
Author

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")


@verajosemanuel
Copy link
Owner

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

@pgensler
Copy link
Author

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?

@verajosemanuel
Copy link
Owner

.First( ) will be run at the start of the R session and .Last( ) will be run at the end of the session.

@pgensler
Copy link
Author

pgensler commented Nov 1, 2017

@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?

@verajosemanuel
Copy link
Owner

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.

@pgensler
Copy link
Author

pgensler commented Nov 2, 2017

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.

@verajosemanuel
Copy link
Owner

verajosemanuel commented Nov 4, 2017

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

@pgensler
Copy link
Author

pgensler commented Nov 5, 2017

@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.

@pgensler
Copy link
Author

pgensler commented Nov 5, 2017

FYI it looks like devtools::install_cran has this functionality, but you need to supply the packages as a character vector

@verajosemanuel
Copy link
Owner

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

@pgensler
Copy link
Author

pgensler commented Nov 5, 2017

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?

@verajosemanuel
Copy link
Owner

just because the time i've included in the dockerfile the only option was github, and had no time to check it all...

@pgensler
Copy link
Author

pgensler commented Nov 8, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants