brodieG / diffobj

Compare R Objects with a Diff
229 stars 12 forks source link

html file disappears before viewing #116

Closed overvolting closed 6 years ago

overvolting commented 6 years ago

It seems by design the temp html output is only available until the enter key is pressed in interactive mode then it is deleted.

The environment I'm using seems to automatically skip this and the html file is always deleted before the browser is launched to view it.

I've tried setting interactive=FALSE and format="html", however the html I get is incomplete and the output looks without the css style that you get in interactive mode.

Any ideas how to solve this issue? Thanks.

brodieG commented 6 years ago

Yes, this is by design to avoid leaving a trail of temp html files.

What environment are you using? The output of sessionInfo() and the environment you're using (terminal, Rstudio, Rgui, etc.). will be helpful.

In the meantime, as a workaround you can use:

f <- tempfile()
writeLines(as.character(diffPrint(1:3, 3:1, format="html")), f)
browseURL(f)

I'm going to add an option in the future to make it possible to preserve the output file.

brodieG commented 6 years ago

Another option:

 diffPrint(1:3, 3:1, format="html", pager="off", style=list(html.output="page"))

But you'll need to capture the output and then use browseURL as well, so not really much better. The reason you don't get the full page is that in non-interactive mode the default format for html.output is not "page".

overvolting commented 6 years ago

Hi Brodie, thanks for your help.

What environment are you using? The output of sessionInfo() and the environment you're using (terminal, Rstudio, Rgui, etc.). will be helpful.

The output from sessionInfo() is below, however it's not very helpful because R is running from within a platform called Statistica and this is the cause of the interactivity fail.

In the meantime, as a workaround you can use:

f <- tempfile() writeLines(as.character(diffPrint(1:3, 3:1, format="html")), f) browseURL(f)

This didn't work because Statistica seems to break the tempfile() function. I get an error saying the file association is invalid.

Another option:

diffPrint(1:3, 3:1, format="html", pager="off", style=list(html.output="page"))

This worked, but the output was not as reading friendly as the default output.

In the end I chose to combine the solutions with something like this:

t1 <- ActiveDataSet[[1]]
t2 <- ActiveDataSet[[2]]
fp1 <- file.path(path.expand("~"),"test.html")
writeLines(as.character(diffPrint(t1,t2,disp.width=250,mode="unified", format="html")), fp1)
browseURL(fp1)

This isn't an ideal solution, because I do like the idea of deleting the temp file after use, but it's a start!

Output of sessionInfo():


R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] daff_0.3.0      diffobj_0.1.9   COMadaptR_1.0-1

loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2    curl_3.2       Rcpp_0.12.16   V8_1.5        
[6] crayon_1.3.4   jsonlite_1.5  ```
brodieG commented 6 years ago

Ah, yes it will be difficult for me to have something that supports R use within statistica, and it seems like a pretty unique case. I'm going to close this issue for now since it seems like you have a workable if not ideal work-around and your use-case is pretty unique.