• Register
0 votes
1.1k views

Problem :

I have the RScript file (let's call it main.r) which has the reference to another file, using the following code:

source("functions.R")

But, when i run a RScript file, it complains with the following error:

Error in file(filename, "r", encoding = encoding) : 
cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'functions.R': No such file or directory

I am sure, my main.R file is next to the functions.R in a same directory. I can call a functions.R in a RMd (RMarkdown) file which exist in a same directory

7 5 2
3,870 points

2 Answers

0 votes

Solution :

I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the very common problem with the people getting started.

In your case just try to add setwd("path/to/project/") in your main.R where path/to/project/ contains the main.R.

Then you can source functions.R either the directly by source("functions.R") if both files lie in a same directory or source("sub-folder/functions.R") if a latter file is contained in the sub-folder.

If you're not working on the RStudio project, chances are a working directory of main.R might be in your home directory.

 

9 7 4
38,600 points
0 votes

Solution:

In your incident attempt to include setwd("path/to/project/") in main.R where path/to/project/ contains main.R.

After you can source functions.R either directly by source("functions.R") in case both files lie in the similar directory or source("sub-folder/functions.R") in case the latter file is sized in a sub-folder.

In case you're not performing on a RStudio project, alters are the performing directory of main.R might be your home directory.

Afterwards discussing with Microsoft Support, the original reason of the problem is to have more than one zip file in the experiment.

As our first 'Execute R Script' module is only doing text cleansing, we determined to remove this first module and its zip file, and do the cleansing within the remaining 'Execute R Script' module.

Currently, with just one zip file it performs fine. According to Microsoft Support, the problem also subsists with Python scripts modules.

The package opens and performs only fine in the regular R Console.

 > mixsiar_gui()
    Loading required package: ggplot2
    Loading required package: gWidgetsRGtk2
    Loading required package: RGtk2
    Loading required package: gWidgets
    Loading required package: cairoDevice
    Loading required package: R2jags
    Loading required package: rjags
    Loading required package: coda
    Linked to JAGS 3.4.0
    Loaded modules: basemod,bugs

    Attaching package: ‘R2jags’

    The following object is masked from ‘package:coda’:

        traceplot

    Loading required package: MASS
    Loading required package: RColorBrewer
    Loading required package: reshape
    Loading required package: lattice
     Show Traceback

     Rerun with Debug
     Error in file(filename, "r", encoding = encoding) : 
      cannot open the connection

    In addition: Warning message:
    In file(filename, "r", encoding = encoding) :
      cannot open file 'build_mix_win.r': No such file or directory

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 246 views
246 views
Problem : I am very new to the R, and after researching my error as below extensively, I am still unable to find the fix for it. I have already checked my working directory, and also made sure that the files are in a correct directory. Error in file(file, "rt") : ... sulfate", 1:10) In addition: Warning message: In file(file, "rt") : cannot open file './specdata001.csv': No such file or directory
asked Jan 4 alecxe 7.5k points
0 votes
1 answer 151 views
151 views
Problem : I am very new to r programming. I have the array and I want to implement the below method: x<-function(b){ if (b>0){ b/sum(b) } else 1 } This method is written to check if there is any value which is larger than the 0 and if it says ... message: &ldquo;Warning message: r the condition has length > 1 and only the first element will be used&rdquo;. How can I fix the above error message?
asked Feb 24 mphil 2.3k points
0 votes
2 answers 639 views
639 views
Problem : I am trying to do some practice on the broom package in R. I ran the below code : kclusts <- data.frame(k=1:9) %>% group_by(k) %>% do(fit=kmeans(data.frame, .$k)) But I have received the below error: Error in as.vector(x, mode) : ... type 'any' I wanted to know whether I am missing something in my above string. Does anyone have the solution on this issue which I am facing currently?
asked Dec 21, 2019 alecxe 7.5k points
0 votes
3 answers 531 views
531 views
Problem : I am trying to coerce a list object to type 'double' Please find below my code: a <- structure(list(`X$Days` = c("10", "38", "66", "101", "129", "185", "283", "374")), .Names = "X$Days") Here a is like $`X$Days` [1] ... however the coercing functions are returning me following error: Error: (list) object cannot be coerced to type 'double' Please let me know how can I resolve the issue.
asked Dec 3, 2019 alecxe 7.5k points
1 vote
1 answer 2.1K views
2.1K views
Problem : I am facing error related to ggproto as following error: cannot add ggproto objects together. did you forget to add this object to a ggplot object?
asked Nov 11, 2019 peterlaw 6.9k points