Difficulty getting started with excel work (Econometrics) in R-studio

Hey everyone, I'm a student of econometrics who is required to use R-studio for assignments in class. However, I started having problems with this software accepting excel files as either .xlsx or .csv files; I keep on getting "use of save versions prior to 2 is deprecated" error when I try loading an excel file as a work session (for using commands to deduce regression variables like standard errors or logarithms).

I was given an assignment that required me to use R-studio. My colleague informed me that she managed to get her answers working by loading the excel file through the load workspace in sessions tab on top.

Problem with excel file type one (xlsx):

I reported this to my professor, who provided me this link:

Quora link (posted below)

I did everything instructed on that topic and still get the same problem as before. I then approach this problem over to stackoverflow and they lock my topic because there isn't enough "details and descriptive" in that topic.

System Information:

  • RStudio Edition: I installed this on my laptop. Not sure if desktop or server.
  • RStudio Version: 1.3.1093.0
  • OS Version: Windows 7
  • R Version: R-4.0.2
  • sessionInfo():
1 Like

Here are links I couldn't post in the above post because of limits here:

Quora link:
https://www.quora.com/How-do-I-install-a-package-in-R-Studio-library-named-“readxl”-so-to-use-it-to-import-excel-file-1

Problem with excel file type two (csv):

So, my response is a bit late because I really got bogged down by annoying assignments from other courses, but here I'm again.

@EconomiCurtis: No, there is a problem with importing data like that and using it. Here is an image file that show cases everything I did before the errors on my first post came to being(using the GUI):

The blue text was the result of the excel file being loaded from the GUI (shown by where my mouse is opening the tabs).

Howegver, the quote thing did install the readr file so thanks for that. Now to carry out the rest of GreyMerchant's instructions.

@Hornetzero, let me know how you continue. As @nirgrahamuk pointed out it should have been quoted.

Its not clear to me that you have had the realisation that if you did not use the GUI loading, but rather wrote that same blue text, the end result would be the same for you. So at the risk of seeming condescending, I'm writing this to underline the point. Hope you don't mind.

I'm still having problems with these files... I'm wondering if its because of the excel files themselves:

and to think that install.packages("readr") would fix this... urghh

The base load() function is for loading R objects, not csv nor excel files. When you are using load() you are neither using readxl package, nor readr package functions.
I think you should read through this forum thread again and identify the functions that you have been recommended to use (none of which were load)

So I tried a different approach... instead of loading an excel file, I just copy pasted the columns using this guy's techniques:

I think I got it right, but the values don't match what I expected from the answer. Here is the image with the correct results compared on the right.

Would anyone know why this is so?

nirgrahamuk, alright thanks. I'm getting conflicting responses from my colleagues who managed to get the software working so I'm really confused about its use. This software was suppose to be taught at university labs, but isn't doable for the current semester because of covid. I have no choice but to slog through this.

No actually, the values match in some areas but not others.

This is an example of how to read your excel file using code

library(readxl)

link <- "https://www.dropbox.com/scl/fi/i9rf1qmfvkhev5td1hmot/hamburger.xlsx?dl=1&rlkey=3z6lsx733udj5zokhicw8acg5"

download.file(link, destfile = "hamburger.xlsx")

(hamburger <- read_excel("hamburger.xlsx"))
#> # A tibble: 12 x 4
#>        q     p   lnq     lnp
#>    <dbl> <dbl> <dbl>   <dbl>
#>  1   892  1.23  6.79  0.207 
#>  2  1012  1.15  6.92  0.140 
#>  3  1060  1.1   6.97  0.0953
#>  4   987  1.2   6.89  0.182 
#>  5   680  1.35  6.52  0.300 
#>  6   739  1.25  6.61  0.223 
#>  7   809  1.28  6.70  0.247 
#>  8  1275  0.99  7.15 -0.0101
#>  9   946  1.22  6.85  0.199 
#> 10   874  1.25  6.77  0.223 
#> 11   720  1.3   6.58  0.262 
#> 12  1096  1.05  7.00  0.0488

Created on 2020-10-26 by the reprex package (v0.3.0.9001)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Hello,

Welcome to the community. Unfortunately, they are very strict on stackoverflow and if you don't have a question setup in a specific way they will simply close it.

Lets start with the .csv read and then we will look at the other one. For the csv one you can simply do the following:

#install.packages("readr")
library(readr)

df_csv <- read_csv("df.csv")

First check that the package can be loaded. If not then remove the # and run the first line. You need to change the df.csv to the name of yours. If this works great. If it doesn't work it might mean that your working directory is not the same as where the file is saved. In that instance you will need to specify the whole path and change the \ to / so it can understand it.

You will see in my code we are reading in the data and allocating it to an object called df_csv. You are able to give it any name. We assign things to objects in this way because then it is evident how they became. You can give it any name.

The excel read should work the same but you might have difficulties finding the package. So let me know if it picks up the install. If it does then the same above should work here.

library(readxl)

df_excel <- read_excel("df.xlsx")

Let me know how you progress.

1 Like

To follow GreyMerchant, I also wanted to point out RStudio has a nice data loading GUI tool built into it.
You can find instructions on how to use that below. A handy part of the tool is that it'll show you the code it used to load your file.


Your second screenshot appears to show that you've successfully loaded the hamburger xlsx file.

If you're curious about the "prior to 2" error message, it's coming from load function. load is not designed to be used with csv or other spreadsheet files.

1 Like

@GreyMerchant I tried those commands, first by checking if the package is loaded, than removing the # and running the first line. The only way the excel file can load successfully is through the GUI, but doing so would not help me run the commands that are needed for my assignment (shown on the picture to EconomicCurtis)

Look again at the blue text in the console in the image you shared where hamburger object is loaded from read_excel function. That is working code, that you can repeat in future R sessions avoiding the gui import helpers.
Sidenote: the red error message relating to attempt to install.packages readr is because library names should be quoted to appear as character strings to that function. install.packages("readr")

1 Like