Creating a file with write.table and file.choose on Mac - r

I am a PC user and have used the write.table (and write.csv) extensively.
I am teaching students how to use R, but some of them use a Mac.
On a PC, the following code:
write.table(mydata, file.choose(), row.names=F, col.names=T)
opens up a browser window, allowing the user to specify the folder where to save the new file, and specify the file name and extension. (Strangely enough, the user is then prompted to click the button "Open" to create a file.)
On a Mac however, it appears there is no way of specifying the name and extension of the file being created, once the window opens. In other words, there does not seem to be a way to actually create a file.
Am I missing something?
Is the solution simply to replace the "file.choose()"
with the full path to the new file?

LGTM:
Having said that, if your student is using RStudio then you would normally need to go to their github repo and file an issue but I've already done that https://github.com/rstudio/rstudio/issues/3903. They seem to intercept the call and pass it to Qt which is not honoring it (it's not a macOS issue but a Qt issue).

Related

Trying to import data into R in a way that will allow anyone to access it when opening the markdown file/ accessing the html knit

I am currently working on a coding project and I am running into trouble with how i Should import the data set. We are supposed to have it read in a way so that our instructor can access our markdown file and be able to import the data and run the code without changing file paths. I know about using relative file paths to make it accessible to anyone, however I don't know how to get around the /users/owner part of the file path. Any help would be greatly appreciated and if you have any further questions feel free to ask.
I've tried changing the working directory to a certain folder that both I and my instructor have named the same thing, however, like I said above, when I use read.csv to import the data frame I am still forced to use the /users/owner filepath which obviously is specific to my computer.
I can understand your supervisor, I request the same from my students. My recommended solution is to put both data and R script (or the .Rmd file) in the same folder. Then one does not need to add a path in the read.csv (or similar) function.
If you use RStudio, move to the folder in the Files pane and then use the gear icon and select "Set as Working Directory".
Then send both files (.R or .Rmd) and the data to the supervisor, ideally as a zip file. The supervisor can then unpack it to an arbitrary folder and just double click to the .R/.Rmd file. The containing folder will then automatically become the working directory.
Other options are:
to use a subfolder for the data or
to put the data to a publicly readable internet location, e.g.
Github and read it directly from there.
The last option requires of course that the data have a free license.

How to browse through the full command history in RStudio

Occasionally I had not saved my source script, and its old version opened. I can find the new version which was executed during the previous session, but only like shreds: I search in history and it shows me a piece of code, but not all lines though they were executed simultaneously. Is there any way to access the complete history, which is definitely stored somewhere, but not shown as a whole? Thanks!
I am using R version 3.6.2 and RStudio Version 1.2.5033.
Search for the "history_database" file. It is an ASCII file and it is usually stored in the folder
C:\Users\username\AppData\Local\RStudio-Desktop
Please, take a look at: https://support.rstudio.com/hc/en-us/articles/200526217-Command-History
use shortcut key Ctrl + 4 to put focus on history or Ctrl+Shift+4 to enlarge window of history. Let us know

bookdown/rmarkdown/knitr: links from PDF to local files and windows/OSX

My bookdown report knitted to PDF tries to link to the underlying results like so
[This](./somedir/.) directory contains some data.
or so
[This file](./somedir/specific_data.txt) contains something more specific.
On (Arch)Linux using okular (my devel environment) all of this just works fine (file manager opens for the first, MIME type defined application for the second link), but on MS Windows and OSX Acrobat Reader asks whether to follow that link and after allowing to do so, the only thing that happens is that the dialog window disappears ...
Is what I want generally impossible on those platforms or am I doing something wrong?
Thanks, Joh
I found the solution:
[This](run:somedirrelativetothedocument/.) directory contains some data.
[This file](run:somedirrelativetothedocument/specific_data.txt) contains something more specific.

How to "save as" programmatically in R?

I've got a Shiny app that produces a product that I'd like my users to be able to save in whatever location they'd like to save it and with whatever name they'd like. In order to do this, I'm currently using file.choose to allow the user to choose a location and file name. On Windows, if it's a new file, the user will be prompted with a message saying this file does not exist and asks if it should be created. On Ubuntu, I believe it was the same outcome. However, this option doesn't work on Mac as there's no way to enter in a new file name and an existing file must be chosen. Additionally, the dialog box says "Open" as opposed to "Save", which is confusing to some users.
Is there a way to trigger the "Save As" dialog box that opens when you save a new file? save, write, and all other functions either come with a predefined file name or expect one to be passed.
Edit
I've come across some questions on SO that attempt to address this with the tcltk package, but I'm not sure I like this solution since there seem to be some issues on Mac OSX with this package. Others recommended using choose.files as there are some customization options you can pass, but this is Windows specific. I'm hoping for a cross-platform option that is intuitive.

Automatically select a submenu in excel

I'm trying to automate some excel processing. With autoit I open several Excel with an add-in. This add-in is used to update data in this excel.
In autoit I managed to open the excel files with the add-in but now I need to select the menuitem to update the excel automatically. I don't have any clue howto do this in autoit3.
I can't find any tutorials or manual howto do this.
It sounds like you would be better off with an Excel macro instead. If you click "tools>macros>record new macro" and set the name of that auto_open then select the cells you want to update and update them and then stop recording, you will have a macro that refreshes the cells every time you open them. If you want a separate file that refreshes all the files you can make a new spreadsheet and start recording and use file open to have opening (or closing) a spread sheet included in the code. Don't forget to have that macro save too.
PS- If you need to open the file without the macro running you need to open excel first then hold shift when you open the file using the "file>open" path.
If you know the keystroke(s) for the menu command, you can use the AutoIt Send function.
For example, the Save function in Excel is CTRL+s.
In AutoIt, that would be:
Send("^s")
I see from your other question on StackOverflow that you are using the ExcelCOM library. You must realize that the MenuItem you are trying to click does some operation on the underlying code in the same way as the ExcelCOM library.
The best solution for your problem is to find out which methods the MenuItem calls, and then reproduce the same behavior with the ExcelCOM library. What you mean by "Update the excel automatically" I don't understand, otherwise I would have found out how to reproduce the behavior by ExcelCOM for you.
If you're using excel 2007 (I am not sure about earlier versions) and higher there is a combination of letters you can use in queue to call (probably) every menu option you want. When you have the excel open - press and release Alt button and you will see letters below main menu options, like in the picture, http://img.photobucket.com/albums/v479/vaeryn/Excel1_zps98c2f450.png Then letter by letter you may dig down the menu option you wish.

Resources