[rkward-users] Detect running in rkward

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Oct 3 14:03:51 UTC 2011


Hi,

On Monday 03 October 2011, Johannes Fichtinger wrote:
> is there a way to understand during runtime of R if the script is running
> through rkward GUI or on the console? The reason is that I want to use the
> multicore package, in particular the mclapply function, which reliably
> produces errors within rkward.

I think the easiest way should be something like
    if ("package:rkward" %in% search ()) ...

Regarding the problem with the multicore package: Yes, that's a known issue 
(http://sourceforge.net/tracker/?func=detail&aid=2866476&group_id=50231&atid=459007), 
and a very annoying one, too. Unfortunately, I do not see any direct solution 
for this in the mid term.

However, alternatives exist, which work reliably in RKWard. Noteably, the 
upcoming R release (2.14) is set to include a package "parallel" for parallel 
computation inside the official base release. As far as I understand, this is a 
more or less unmodified copy of packages "snow" and "multicore". The "snow" 
portion (functions make[PSOCK]Cluster(), parLapply() and friends) works well 
in RKWard (to the best of my testing). parLapply() even allows spreading 
calculations to several computers across the network, and is also portable to 
windows.

> So I want to do in my .r file something like
> 
> if (RUNNING_WITHIN_R) {
> 	lapply(…)
> } else {
> 	mclapply(…)
> }

If you want to stick with multicore / mclapply, I think
    options(cores=1)
should do the trick, without the need to wrap all uses of mclapply() into an 
if() statement.

Regards
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/rkward-users/attachments/20111003/64ff3693/attachment.sig>


More information about the Rkward-users mailing list