I'm familiar with the the commands file.path()
and the new here()
package in R to make working with collaborators and different OS environments. But I'm afraid I can't figure out how to write a script that would save a basic .csv file to the user's desktop, regardless of whether the user is using a mac or OS system.
Basically, this is a setup script for a tutorial I am giving. I would like to send this to students before-hand so that they install the necessary packages. I would like to check that this has worked so my idea is to have them write out a csv file with the names of the installed packages. A version of the code is below. Could I use something like Sys.info()
to tell if it is running on a Mac or PC and construct an ifelse()
command?
#Necessary libraries
to.install<-c('tidyverse')
#Packages that have not been installed
new.packages <- to.install[!(to.install %in% installed.packages()[,"Package"])]
#If there are packages that must be installed, this installs them
if(length(new.packages)) install.packages(new.packages, repos='http://cran.utstat.utoronto.ca/')
#Save installed packages in out
out<-to.install[to.install %in% installed.packages()[,'Package']]
#Check
out
#Write out to desktop. How do I do this in platform independent way?
#write.csv(out, '~/Desktop/test.csv')
#library(here)
#here()