Problem with R downloading zipped ACS data files - r

I have been having a problem trying to download a zipped file with American Community Survey (ACS) data. The file is a zipped folder that contains zipped sub-folders within it. I want to download and unzip the file leaving the individual zipped sub-folders. The code I am using is:
ACS.url<-"https://www2.census.gov/programs-surveys/acs/summary_file/2019/data/5_year_entire_sf/Tracts_Block_Groups_Only.zip"
dir<-getwd()
zip.file<-"CTrctACS19.zip"
zip.combine<-as.character(paste(dir,zip.file,sep="/"))
download.file(ACS.url,destfile=zip.combine,mode="wb")
unzip(zip.file)
After running the code I get what appears to be a correct download, but the unzip does not work. I get the following error message:
In unzip(zip.file) : error 1 in extracting from zip file
The downloaded file is only about half of the size zip of the file I am trying to download (the original is 3.7G at Census website but I have about 1.8G) so I think it is not downloading the data correctly. I tried to access the downloaded file with the winzip program and it would not work either. I can download files from that website if they are smaller and don't include zipped subfolders. Any help would be appreciated.

Related

Download specific file from tar.gz

I want to extract and download a file from a tar.gz archive, from a web server, but without first downloading the entire archive, because it is large, about 3 GB. I am using a Unix-like environment. How can I achieve this with either a shell command or a with a Python module?
Related tools:
5 Ways to Preview ZIP and Download Selected Files in Archive, On Windows
Related questions:
Download specific folder from tar.gz file using wget command
How to download only a single file from an online ZIP archive via Powershell?

Error uploading asset to Google Earth Engine

I am trying to upload a simple shapefile to my assets in Google Earth Engine (GEE). Since I started studying GEE I found these errors when uploading some .shp files:
"Error: Multiple primary files found."; and
"Error: Could not unzip file."
Both errors happened to the same asset, and also for some other assets.
All .shp and auxiliary files were compressed to .zip
These are the files I got compressed + the .zip file itself:
In a single upload, you must upload exactly one shapefile .shp, and its auxiliary files (.shx, .dbf, .prj, and so on). You cannot upload multiple shapefiles at once.

loading downloaded data to Rstudio

mission on online course:
Download this RData file to your working directory. Then load the data into R with the following command:
load("skew.RData")
so I have downloaded it to my computer but where is my working directory? or how do I load the downloaded file to Rstudio
You can see your working directory by executing getwd().
In order to load the data you need to change it to the folder path where the data is stored.
setwd("C:/your/path")
load("skew.RData")
You can set you working directory in RStudio on the right side manually and then save the files there and open them like :
load("skew.RData")
If your file is saved somewhere else, you should define the path to it:
load("path/to/your/file/skew.RData")

R code asking Excel to open a file

Here is a real world setting:
We download *.xls or *.xlsx files from the web.
We open the *.xls or *.xlsx files by double-clicking the files one by one (assuming Excel is installed) in order to eye-ball the file content.
This could become tedious (relatively speaking) if a lot of excel files were downloaded regularly, filed into different directories and need to check the file content one by one.
For example, we downloaded a file as below:
url <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FDATA.gov_NGAP.xlsx"
file01 <- file.path(getwd(), "NGAP.xlsx")
download.file(url, file01, mode = "wb")
What is the R code to instruct Excel to open this file? Of course we could go to download directory and double-click the file to open it. But want to instruct Excel to open the file by running R code. Thanks for any pointers provided!
The base function file.show opens files with the default application registered to handle the given file extension.
u <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FDATA.gov_NGAP.xlsx"
download.file(u, f <- tempfile(fileext='.xlsx'), mode = "wb")
file.show(f)

Read Doc file and file path from Browser

I have an issue that I want to read a DOC file in my system but the condition is
Suppose you are working on browser and download some PDF or DOC file ,then my program should run and get the path of that file and convert that doc file in binary format.
the file download path may be change because some time it download in default folder but some times you saves that file in other locations.
my concern is this that code should execute at download time and should get file path from download history and read that file.

Resources