Skip to content
Prev 360859 / 398506 Next

Antwort: Re: Antwort: Re: Antwort: Re: Re: sink(): Cannot open file (SOLVED)

Hi Henrik, Jim, Sarah, Duncan,
Hi All,

I have tried the built-in solution using PowerShell:

$lockedFile="C:\Windows\System32\wshtcpip.dll" 
Get-Process | foreach{$processVar = $_;$_.Modules | foreach{if($_.FileName 
-eq $lockedFile){$processVar.Name + " PID:" + $processVar.id}}}

It did not show any processes.

Then I tried the solution using "RessourceMonitor". There I found two 
processes:

rstudio.exe
rsession.exe

Right-clicking on rstudio.exe and selecting "Warteschlange analysieren" (= 
analyse queue?) showed nothing. Right-clicking on rsession.exe and 
selecting "Warteschlage" said:

"Mindestens ein Thread von rsession.exe wartet auf die Fertigstellung von 
Netzwerk E/A". (= "At least one thread of "rsession.exe" is waiting for 
finishing a network i/o operation").

Putting rsession.exe into the search field of the handles tap of 
RessourceMonitor gave no results. No handles were identified.

I can not follow the suggestions where installation of software is 
required due to security rules of the company I work for.

I had a look at different R versions on my machine:

1) R i386 3.2.2
2) R i386 3.2.4 (revised)
3) R i386 3.2.5
4) R x54 3.2.2
5) R x64 3.2.4 (revised)
6) R x64 3.2.5

I did 

## capture all the output to a file.
zz <- file("C:/Temp/all.Rout", open = "wt")
sink(zz)
sink(zz, type = "message")
try(log("a"))
## back to the console
sink(type = "message")
sink()
unlink("C:/Temp/all.Rout")

on R i386 3.2.2 and R x64 3.2.2 directly without RStudio. In both cases 
the file was locked.

Adding

close(zz)

solved the problem in both versions.

Encouraged by this I tired (successivly refered to as "complete code")

## capture all the output to a file.
zz <- file("C:/Temp/all.Rout", open = "wt")
sink(zz)
sink(zz, type = "message")
try(log("a"))
## back to the console
sink(type = "message")
sink()
unlink("C:/Temp/all.Rout")
close(zz)

on R i386 3.2.4 (revised) and R x64 3.2.4 (revised) without RStudio. Works 
in both cases. The same with R i386 3.2.5 and R x64 3.2.5 each without 
RStudio.

It did the same with RStudio altering the R version in the RStudio session 
using "complete code". The results are:

R i386 3.2.2: OK
R. x64 3.2.2: OK
R i386 3.2.4 (revised): OK
R x64 3.2.4 (revised): OK
R i386 3.2.5: OK
R x64 3.2.5: OK

This got me lost. I had tried the complete code the last days a hundred 
times. It never worked.

Then I restarted my machine powering up RStudio x64 3.2.5 using the 
"complete code" and ... it worked.

I have no idea what was wrong the last days.

As far as I can say today the documentation of ?sink in R is currently

## capture all the output to a file.
zz <- file("all.Rout", open = "wt")
sink(zz)
sink(zz, type = "message")
try(log("a"))
## back to the console
sink(type = "message")
sink()
file.show("all.Rout")

and should be - in my opinion  - supplemented with

close(zz).

Any thoughts?

Kind regards

Georg




Von:    Henrik Bengtsson <henrik.bengtsson at gmail.com>
An:     G.Maubach at weinwolf.de, 
Kopie:  Duncan Murdoch <murdoch.duncan at gmail.com>, "r-help at r-project.org" 
<r-help at r-project.org>
Datum:  11.05.2016 21:48
Betreff:        Re: [R] Antwort: Re: Antwort: Re: Re: sink(): Cannot open 
file



Sounds like it would be helpful to find out exactly which process is
holding on to the file in order to figure out what's going on. From a
quick look, it seems that

  
http://superuser.com/questions/117902/find-out-which-process-is-locking-a-file-or-folder-in-windows


gives some useful info on how to track down the process that looks the 
file.

/Henrik
On Wed, May 11, 2016 at 9:47 AM, <G.Maubach at weinwolf.de> wrote:
use
in
http://www.R-project.org/posting-guide.html
Message-ID: <OFA229D574.A03C2E31-ONC1257FB1.0027B67C-C1257FB1.002D39CA@lotus.hawesko.de>
In-Reply-To: <CAFDcVCTksQ9EmqH_O5GGd1ubOq9M+SDmV2NSHRp0X2i=vNbpnw@mail.gmail.com>