Hi
I am generating a graph jpeg file using a function R. I m using this
script
a<- 1:10
b <- 1:10
jpeg("mygraph.jpeg")
{
plot(a,b)
}
dev.off()
If by some chance I do miss some values suppose for a , the file gets
created initially and then we do not plot anything in it. This file now
becomes corrupted and we cannot delete this file from current R Session.
I Have tried commands like file.remove() and unlink to remove the corrupt
file from current R session.
Is there any other way inorder to remove such files??
Thanks & Regards,
Vikrant
--
View this message in context:
http://r.789695.n4.nabble.com/Removing-Corrupt-file-tp3092178p3092178.html
Sent from the R help mailing list archive at Nabble.com.
Vikrant,
if you execute the code inside a function like
jpegplotfun <- function (a, b){
jpeg("mygraph.jpeg")
plot(a,b)
dev.off()
}
the dev.off () is not executed if an error occurs before. So the problem is
basically that the jpeg file is still open (you may noticed open devices in R as
left overs of these errors).
See ? try and ? on.exit for ways to deal with situations where you need to
clean up after errors.
HTH,
Claudia
On 12/17/2010 08:24 AM, vikrant wrote:>
> Hi
> I am generating a graph jpeg file using a function R. I m using this
> script
> a<- 1:10
> b<- 1:10
> jpeg("mygraph.jpeg")
> {
> plot(a,b)
> }
> dev.off()
>
>
> If by some chance I do miss some values suppose for a , the file gets
> created initially and then we do not plot anything in it. This file now
> becomes corrupted and we cannot delete this file from current R Session.
> I Have tried commands like file.remove() and unlink to remove the corrupt
> file from current R session.
> Is there any other way inorder to remove such files??
>
>
>
> Thanks& Regards,
> Vikrant
>
>
--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Universit? degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste
phone: +39 0 40 5 58-37 68
email: cbeleites at units.it
On Dec 17, 2010, at 2:24 AM, vikrant wrote:> > Hi > I am generating a graph jpeg file using a function R. I m using this > script > a<- 1:10 > b <- 1:10 > jpeg("mygraph.jpeg") > { > plot(a,b) > } > dev.off() > > > If by some chance I do miss some values suppose for a , the file gets > created initially and then we do not plot anything in it.This is not making sense, see below.> This file now > becomes corrupted and we cannot delete this file from current R > Session. > I Have tried commands like file.remove() and unlink to remove the > corrupt > file from current R session. > Is there any other way inorder to remove such files??There was a question earlier this week that may have provoked an answer that applies: ?graohics.off # followed by file.remove() But I am puzzled. I would not have expected missing values in vectors offered to a plot command to have resulted in a corrupted file and I am unable to reproduce the behavior when I insert missing values into the "a" vector. This suggests you may have more fundamental problems with your installation of R (about which you have not provided the requested information). -- David.> > > > Thanks & Regards, > Vikrant > > > -- > View this message in context: http://r.789695.n4.nabble.com/Removing-Corrupt-file-tp3092178p3092178.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT