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

Leftovers from old file in saveHTML #113

Open
ugroempi opened this issue Feb 11, 2018 · 6 comments
Open

Leftovers from old file in saveHTML #113

ugroempi opened this issue Feb 11, 2018 · 6 comments

Comments

@ugroempi
Copy link

ugroempi commented Feb 11, 2018

I encountered some problems arising from left-overs of an old saved html file of the same name. The situation: I ran the code below initially with black squares, with img.name="blacksquare". I then changed to circles, changing the name to img.name="blackcircle", but keeping the html file name. Viewing the html file in the browser showed an animation at the top which tried to find file "blacksquare1.png" (but of course didn't and displayed a placeholder instead), and below that the intended animation with the circles (the Rstudio window did not display either of the animations properly); thus, saveHTML behaved as though there were an append option somehow, which seems like a bug to me.

Best, Ulrike

The code:
ani.options(imgdir="images", ani.dev="png", use.dev=TRUE, interval=0.1, nmax=38)
greys20 <- grey.colors(20, start=0.2, end=0.9)

saveHTML(
for (i in c(20:1, 2:19)){
plot.new()
par(mar=rep(1,4), bg="grey20")
plot.window(xlim=c(-1.25,1.25), ylim=c(-1.25,1.25), asp=1)
symbols(0, 0, circles=1, inches=FALSE,
bg=greys20[i], fg=greys20[i], add=TRUE)},
img.name = "blackcircle", htmlfile = "blackmovie.html",
title="Crude animation", navigator=FALSE)

@ugroempi
Copy link
Author

Not sure, might be spurious, from an unclosed device, and thus not a problem of this package.
Best, Ulrike

@yulijia
Copy link
Collaborator

yulijia commented Feb 12, 2018

I tested your demo twice with img.name = "blacksquare" or img.name = "blackcircle", and keeping the html file name as same, I didn't see any a placeholder image.

@ugroempi
Copy link
Author

I believe that a file called blacksquare0.png was created from an (erroneously) open device while running the code for creating the blackcircle1.png ... files (and possibly, while img.name was not yet reset to blackcircle); the top of the html file then showed a one-slide animation of this stray file, before showing the intended animation of the circles. This certainly was not a standard condition, and saveHTML cannot be expected to foresee it.

Maybe this could be avoided by setting img.name in a separate call to ani.options before calling saveHTML, rather than as an option within saveHTML ?

Best, Ulrike

@yulijia
Copy link
Collaborator

yulijia commented Feb 12, 2018

Yes, I think there are some problems in saveHTML, I am checking it now. I didn't find blacksquare0.png in my directory. I am checking why the two animations were displayed in one html file.

Here is my code.

ani.options(imgdir="images", ani.dev="png", use.dev=TRUE, interval=0.1, nmax=38)
greys20 <- grey.colors(20, start=0.2, end=0.9)

saveHTML(
  for (i in c(20:1, 2:19)){
    plot.new()
    par(mar=rep(1,4), bg="grey20")
    plot.window(xlim=c(-1.25,1.25), ylim=c(-1.25,1.25), asp=1)
    symbols(0, 0, circles=1, inches=FALSE,
            bg=greys20[i], fg=greys20[i], add=TRUE)},
  img.name = "blacksquare", htmlfile = "blackmovie.html",
  title="Crude animation", navigator=FALSE)



ani.options(imgdir="images", ani.dev="png", use.dev=TRUE, interval=0.1, nmax=38)
greys20 <- grey.colors(20, start=0.2, end=0.9)

saveHTML(
  for (i in c(20:1, 2:19)){
    plot.new()
    par(mar=rep(1,4), bg="grey20")
    plot.window(xlim=c(-1.25,1.25), ylim=c(-1.25,1.25), asp=1)
    symbols(0, 0, circles=1, inches=FALSE,
            bg=greys20[i], fg=greys20[i], add=TRUE)},
  img.name = "blackcircle", htmlfile = "blackmovie.html",
  title="Crude animation", navigator=FALSE)

@yulijia
Copy link
Collaborator

yulijia commented Feb 12, 2018

In saveHTML, if we create multiple animations with same htmlfile name, we try to add new animation after the old animation in the same file, although we don't show any append option.

  ## try to append to the HTML file if it exists
  html = if (file.exists(htmlfile)) {
    readLines(htmlfile)
  } else {
    readLines(system.file('misc', 'scianimator', 'index.html', package = 'animation'))
  }

@ugroempi
Copy link
Author

ugroempi commented Feb 13, 2018

I see! I observe that appending does not happen for the same img.name, only if the img.name is different with the same htmlfile. This is something I would not want to happen unasked; why not have an append option with default TRUE and if (file.exists(htmlfile) && append)? At least, the behavior should be explained in the documentation, I think.

Best, Ulrike

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