R Cheatsheet: Files and Directories

Check whether a directory exists, if true then nothing happen




Next Step, write a function that downloads a csv file from the internet:


#Check if a directory exists, otherwise we create 
 #Next step, download a file from the internet.
 #First we create a variable with the url which contains the data:
 #Next variable containts the location of local copy of downloaded file
 #In order to obtain an online file we must use the download.file() function
 #Since we are working from a Windows terminal the third parameter (method) should work
 #with the default value. If you're working from a Mac, then you must specify its value to "curl"
 #because that file is available via https protocol
 download.file(fileURl,destfile = localcopy)
 #we check the files in that directory
 #Finally we print the date we downloaded that file. This is very important specially because you need
 #to be able to keep track of that file.

After executing this function we obtain as a result:


Now we check the existence of the new file using the File Explorer:


Etiquetas:, ,

Acerca de martincx

Fútbol, cine, historia y literatura. Quejándome del fútbol moderno. Ojalá y escribir fuera un trabajo remunerado.

Este blog se enriquece con los comentarios, deja acá tu impresión.

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: