Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knitting to Word causes both Word and Preview.app to open on OSX with latest Office 365 update #5148

Open
nigeljonez opened this issue Jul 26, 2019 · 3 comments

Comments

@nigeljonez
Copy link

@nigeljonez nigeljonez commented Jul 26, 2019

System details

RStudio Edition : Desktop
RStudio Version : 1.2.1335
OS Version      : macOS Mojave 10.14.6
R Version       : 3.6.1
Microsoft Word  : Version 16.27 (19071500); Office 365

Steps to reproduce the problem

(Tested with fresh OS X installation)

  1. Install currently available R, RStudio & Microsoft Office packages on macOS
  2. Create a new R Markdown file - the default without any edits is suitable for this issue
  3. Using the Knit menu, "Knit to Word"
  4. Observe that Microsoft Word launches (to the new document screen), and momentarily afterwards Preview.app also opens with the knitted document.

Describe the problem in detail

Essentially, what we are seeing is that on Mac computers which have been updated to include the latest build of Microsoft Word are having issues opening knitted documents. (I suspect people that have freshly setup their computer for the start of the NZ semester, I don't think this build of Word has gone out via the Autoupdate Utility - I couldn't reproduce this issue until I redownloaded Word)

In particular, while RStudio is triggering the launch of Microsoft Word, the document does not open, instead the OSX Preview app launches with the document, this is quite confusing for students (especially as Preview.app strips equations & potentially other formatting (equations are the obvious ones for us).

For an indication of prevalence, we've just noticed this after running a series of labs, of around 50-70 students with Macs there were at least 3-5 installations already with this issue.

I've also performed a screen recording (Google Drive link) of this issue, where you can see Word launch to the new document screen (behind RStudio) and Preview.app open.

Describe the behavior you expected

The past behaviour, RStudio to open Microsoft Word and load the knitted document.

Additional Notes

I was going to try to get RStudio to compile from source and debug & see if there was a quick fix for this but had a lot of trouble getting a compiled copy to work, however I did look at the following:

I have noticed that the method for launching Word on Mac's is via AppleScript as in

tell application "Microsoft Word"
activate
set reopened to false
repeat with i from 1 to (count of documents)
set docPath to full name of document i
if POSIX path of docPath is equal to "%@" then
set w to active window of document i
set h to horizontal percent scrolled of w
set v to vertical percent scrolled of w
close document i
set d to open file name docPath with read only
set reopened to true
set w to active window of d
set horizontal percent scrolled of w to h
set vertical percent scrolled of w to v
exit repeat
end if
end repeat
if not reopened then open file name POSIX file "%@" with read only
end tell

Replicating the very basic form of this in the AppleScript Editor:

tell application "Microsoft Word"
	activate
	set d to open file name "/Users/njones/Documents/Stats/Untitled.docx" with read only
end tell

Loads the knitted document successfully, (The above path is the path to the knitted document). Therefore my suspicion is that Word is no longer handling the path format RStudio is substituting %@ with.

The Preview.app portion of the issue seems to be a result of

if (!showOfficeDoc(path, @"Microsoft Word",
[NSString stringWithUTF8String: s_openWordDocumentFormatString]))
{
showFile(qPath);
};
which makes me think the AppleScript is triggering errors.

@jmcphers jmcphers added the macos label Jul 26, 2019
@ronblum

This comment has been minimized.

Copy link

@ronblum ronblum commented Jul 29, 2019

@nigeljonez Are you using a bookdown project, by chance? I'm able to reproduce the problem with Word 16.27 (19071500) when using bookdown, going back even to RStudio Desktop 1.1.463. However, it works fine both when not in a project and a plain project with some Rmd files.

@nigeljonez

This comment has been minimized.

Copy link
Author

@nigeljonez nigeljonez commented Jul 29, 2019

@ronblum No, I can trigger this using the standard RMarkdown file created with New->R Markdown (the document in the screen capture was created this way). I've just tried again and reproduced it this way too. In my cases I've saved to a place other than my current working directory. Although I have also reproduced the issue with opening RStudio by opening the Rmd file via Finder as well.

@ronblum

This comment has been minimized.

Copy link

@ronblum ronblum commented Jul 30, 2019

@nigeljonez OK, good to know. At least we can both reproduce it in some way. I've marked it as a bug to review as we continue development of RStudio. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.