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 in Data Analytics by Sophie may
• 9,870 points
42 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 by Tyrion anex
• 8,280 points

Related Questions In Data Analytics

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,690 points
34 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,550 points
662 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 in Data Analytics by anonymous
• 31,840 points
109 views
0 votes
1 answer

How to read R errors through JRI

You'll be able to perform those R-Expressions, ...READ MORE

answered Nov 8, 2018 in Data Analytics by Maverick
• 10,040 points
31 views
0 votes
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21 in Data Analytics by anonymous
• 31,840 points
146 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 Anmol
• 3,620 points
70 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 Anmol
• 3,620 points
37 views
0 votes
1 answer

How do I import document files in R programming

Try the following: read.table("~/SMSSpamCollection", header=TRUE, sep="\t") Change "~/" to the "ptah/to/your/file/" Mess around ...READ MORE

answered Nov 5, 2018 in Data Analytics by Kalgi
• 42,330 points
36 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,280 points
73 views
0 votes
2 answers