// // ConsoleCtrl.m // RDemo // // Created by Simon Urbanek on 10/14/12. // Copyright (c) 2012 Simon Urbanek. All rights reserved. // #import "ConsoleCtrl.h" #import "REngine.h" @implementation ConsoleCtrl /* initialize R on startup * NOTE: R_HOME and R_ARCH settings are hard-coded for CRAN build of R */ - (void) awakeFromNib { #ifdef __x86_64__ const char *arch = "/x86_64"; #elif defined __i386__ const char *arch = "/i386"; #elif defined __ppc__ const char *arch = "/ppc"; #else #error "Unsupported architecture" #endif setenv("R_HOME", "/Library/Frameworks/R.framework/Resources", 1); setenv("R_ARCH", arch, 1); engine = [[REngine alloc] initWithHandler: self]; [engine activate]; } /* we only implement WriteConsole so we see some output, nothing else is implemented !! */ - (void) handleWriteConsole: (NSString*) msg withType: (int) oType { NSTextView *console = (NSTextView*)[self view]; [console setString: [[console string] stringByAppendingString: msg]]; } /* all those should be implemented if this is to work like a GUI .. */ - (char*) handleReadConsole: (int) addtohist { return NULL; } - (void) handleBusy: (BOOL) which {} - (void) handleFlushConsole {} - (void) handleWritePrompt: (NSString*) prompt {} - (void) handleProcessEvents {} - (int) handleChooseFile: (char*) buf len: (int) length isNew: (int) new { return -1; } - (void) handleShowMessage: (char*) msg {} - (void) handleProcessingInput: (char*) cmd {} - (int) handleEdit: (char*) file { return -1; } - (int) handleEditFiles: (int) nfile withNames: (char**) file titles: (char**) wtitle pager: (char*) pager { return -1; } - (int) handleShowFiles: (int) nfile withNames: (char**) file headers: (char**) headers windowTitle: (char*) wtitle pager: (char*) pages andDelete: (BOOL) del { return -1; } @end