Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Aug 6, 2016
1 parent 763bd09 commit d92d190
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 184 deletions.
Binary file added QuickLookR.qlgenerator.zip
Binary file not shown.
4 changes: 0 additions & 4 deletions QuickLookR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
C4291BF11D552859001238D2 /* GeneratePreviewForURL.m in Sources */ = {isa = PBXBuildFile; fileRef = C4291BF01D552859001238D2 /* GeneratePreviewForURL.m */; };
C4291BF31D552859001238D2 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = C4291BF21D552859001238D2 /* main.c */; };
C4291BFB1D552C7A001238D2 /* QuickLookR.qlgenerator in CopyFiles */ = {isa = PBXBuildFile; fileRef = C4291BEB1D552859001238D2 /* QuickLookR.qlgenerator */; };
C4291C171D552E27001238D2 /* rdata.h in Headers */ = {isa = PBXBuildFile; fileRef = C4291C161D552E27001238D2 /* rdata.h */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -33,7 +32,6 @@
C4291BF01D552859001238D2 /* GeneratePreviewForURL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GeneratePreviewForURL.m; sourceTree = "<group>"; };
C4291BF21D552859001238D2 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
C4291BF41D552859001238D2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C4291C161D552E27001238D2 /* rdata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rdata.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -70,7 +68,6 @@
C4291BF01D552859001238D2 /* GeneratePreviewForURL.m */,
C4291BF21D552859001238D2 /* main.c */,
C4291BF41D552859001238D2 /* Info.plist */,
C4291C161D552E27001238D2 /* rdata.h */,
);
path = QuickLookR;
sourceTree = "<group>";
Expand All @@ -82,7 +79,6 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
C4291C171D552E27001238D2 /* rdata.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
47 changes: 19 additions & 28 deletions QuickLookR/GeneratePreviewForURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,52 @@

#import <Cocoa/Cocoa.h>

#include "rdata.h"
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);

/* -----------------------------------------------------------------------------
Generate a preview for file
This function's job is to create preview for designated file
----------------------------------------------------------------------------- */

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
//' This does the hard work
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) {

@autoreleasepool {

NSURL *myURL = (__bridge NSURL *)url;
NSURL *myURL = (__bridge NSURL *)url ;

NSString *contents = [ myURL absoluteString ];
NSString *contents = [ myURL absoluteString ] ;

NSLog(@"generate preview for %@", contents);
NSLog(@"Generating preview for %@", contents) ;

//int pid = [[NSProcessInfo processInfo] processIdentifier];
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *file = pipe.fileHandleForReading;
NSPipe *pipe = [ NSPipe pipe ] ;
NSFileHandle *file = pipe.fileHandleForReading ;

NSString *cmd = @"rdatainfo::get_info('" ;
cmd = [ cmd stringByAppendingString: contents ] ;
cmd = [ cmd stringByAppendingString: @"')" ] ;

NSTask *task = [[NSTask alloc] init];
NSTask *task = [ [ NSTask alloc ] init] ;
task.launchPath = @"/usr/local/bin/Rscript";
task.arguments = @[@"-e", cmd];
task.arguments = @[ @"-e", cmd ];
task.standardOutput = pipe;

[task launch];

NSData *data = [file readDataToEndOfFile];
[file closeFile];
NSData *data = [ file readDataToEndOfFile ] ;
[ file closeFile ];

NSString *rOutput = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSString *rOutput = [ [ NSString alloc ] initWithData: data encoding: NSUTF8StringEncoding ] ;

if (false == QLPreviewRequestIsCancelled(preview)) {
QLPreviewRequestSetDataRepresentation(preview,
(__bridge CFDataRef)([rOutput dataUsingEncoding:NSUTF8StringEncoding]),
kUTTypePlainText,
NULL);
(__bridge CFDataRef)([ rOutput dataUsingEncoding:NSUTF8StringEncoding ]),
kUTTypePlainText, NULL) ;
}

}

return noErr;

}

void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview)
{
// Implement only if supported
}
void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) { }
8 changes: 4 additions & 4 deletions QuickLookR/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<dict>
<key>public.filename-extension</key>
<array>
<string>GGG</string>
<string>RData</string>
<string>rdata</string>
<string>rda</string>
<string>rds</string>
</array>
</dict>
</dict>
Expand All @@ -38,9 +38,9 @@
<dict>
<key>public.filename-extension</key>
<array>
<string>GGG</string>
<string>RData</string>
<string>rdata</string>
<string>rda</string>
<string>rds</string>
</array>
</dict>
</array>
Expand Down
148 changes: 0 additions & 148 deletions QuickLookR/rdata.h

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is a macOS QuickLook Plugin for R data files.

That means if you install this plugin (download and unzip `QuickLookR.qlgenerator.zip` and put `QuickLookR.qlgenerator` into `~/Library/QuickLook`) you can hit the spacebar on an R Data or saved RDS file (`.rdata`, `.rda`, `.rds` are currently supported extensions) and get a `str()` preview without firing up R/RStudio.

It looks for `Rscript` in `/usr/local/bin` and (for now) requires a helper package [`rdatainfo`](https://github.com/hrbrmstr/rdatainfo). `devtools::install_github("hrbrmstr/rdatainfo")` to install that.

For the moment, the QuickLook preview is rather plain, but I hope to improve the output and switch to reading the data files at the C-level by linking directly to `R.framework`.

0 comments on commit d92d190

Please sign in to comment.