R Programming - Unable to read files

0 votes

I've written an R program that reads multiple csv files. This code works if I give 'read.csv' command but it never works if I pass the name of the file as a parameter.

For example

dat <- function (x)  
 {     
awr <- data.table(read.csv(x))
  }

I passed

dat("hello.csv")

However, I'm not getting any error and the awr data set is not getting created.

For example:

awr <- data.table(read.csv("hello.csv")) ..it works...

Why is it not working when passed in the function?

Apr 15, 2019 in Data Analytics by Sophie may
• 10,100 points
65 views

1 answer to this question.

0 votes

This is happening because you're not returning any value from the function, try this:

dat <- function (x) data.table(read.csv(x)) 

answered Apr 15, 2019 by Tyrion anex
• 8,550 points

Related Questions In Data Analytics

+4 votes
0 answers

I was unable to cluster the data points using dbscan in R programming

After using dbscan package I was given with ...READ MORE

Feb 1 in Data Analytics by ramthotahappy
• 160 points
244 views
0 votes
1 answer

How can I use R to list all files with a specified extension ?

fls <- list.files(pattern = "\\.dbf$") $ at the ...READ MORE

answered May 10, 2018 in Data Analytics by zombie
• 3,750 points
126 views
0 votes
1 answer

Unable to install the 'devtools' package in R

Run the below command in your Ubuntu/Linux ...READ MORE

answered Jun 6, 2018 in Data Analytics by Bharani
• 4,560 points
950 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 32,490 points
1,369 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 32,490 points
404 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,680 points
188 views
0 votes
1 answer

How can I perform word stemming in R

The tm package in R provides the stemDocument() function to stem the ...READ MORE

answered Aug 20, 2018 in Data Analytics by Abhi
• 3,680 points
308 views
0 votes
1 answer

How to know the type of an object?

To find the type of an object ...READ MORE

answered Sep 19, 2018 in Data Analytics by Abhi
• 3,680 points
65 views
0 votes
1 answer

R programming: How to pass variables from a r program to mysql function?

To include the R variables called start.date and end.date, you can use paste to ...READ MORE

answered Dec 28, 2018 in Data Analytics by Tyrion anex
• 8,550 points
201 views
0 votes
2 answers

How to change the value of a variable using R programming in a data frame?

You are getting this error since the ...READ MORE

answered Aug 16, 2019 in Data Analytics by anonymous
• 32,490 points
12,727 views