I've explored but didn't find any suggestions. I want to know how to save an empty file to adlsgen2 using R and then read it back to the same code. Thanks for the help.
Asked
Active
Viewed 103 times
0
-
It looks like you're fairly new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample code you've attempted, listing non-base R packages, any errors/warnings received, sample data, like the output from `dput(head(dataObject)))`, and what type of output you are expecting. Check it out: [making R questions reproducible](https://stackoverflow.com/q/5963269). – Kat May 23 '22 at 14:17
2 Answers
0
Since you want to write an empty file to ADLS gen2 using R and read it from that location, first create a dataframe.
- The dataframe can either be completely empty, or it can be a dataframe with column names but no rows. You can use the following code to create one.
df <- data.frame() #OR
df <- data.frame(<col_name>=<type>)
- Once you have created a dataframe, you must establish connection to ADLS gen2 account. You can use the method specified in the following link to do that.
- After making the connection you can use read and write functions in R language using the path to ADLS gen2 storage. The following link provides numerous functions that can be used according to your requirement.
https://www.geeksforgeeks.org/reading-files-in-r-programming/

Saideep Arikontham
- 5,558
- 2
- 3
- 11
0
Sharing the solution to my question:
I've used SparkR to create an empty data frame and save the same in the adls after setting up the spark context.
Solution is below:
Step 1: Create a schema
fcstSchema <- structType(structField("ABC", "string",TRUE))
new_df<- data.frame(ABC=NULL,stringsAsFactors=FALSE)
n<-createDataFrame(new_df,fcstSchema)
SparkR::saveDF(n,path = "abfss://<account_name>@<datalake>.dfs.core.windows.net/<path>/",source = "delta",mode = "overwrite")

hamagust
- 728
- 2
- 10
- 28

Manish Kumar Biswas
- 11
- 2