rmarkdown and source call to R file.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

rmarkdown and source call to R file.

R help mailing list-2
Hi!
I'm new in R and this list.
I made a shiny app using R studio.
my files are:
   -server.R
   -ui.R
   -helper.R
   -Report.Rmd.

All the files are on the same directory and helper.R is a file that
contains a lot of functions used in Report.Rmd and server.R

for some reason I cant call from Report.Rmd the file helper.R

My code in Report.Rmd is

   ## Summarize table
   ```{r, echo=FALSE}
   library(knitr)
   source("helper.R", local = knitr::knit_global())
   summarized_table<-give_table(params$ldf_summary)
   kable(summarized_table,"simple")
   ```
If I use absolute path it works but since I want to upload it to
https://www.shinyapps.io/ I must make it work with relative path.

The message I get is:

   processing file: Report.Rmd
   
   |..........................                                        
                                        |  25%
     ordinary text without R code

   
   |....................................................              
                                        |  50%
   label: unnamed-chunk-1 (with options)
   List of 1
    $ echo: logi FALSE

   Quitting from lines 13-17 (Report.Rmd)

   Warning: Error in file: cannot open the connection
     [No stack trace available]


The funny thing is that if I put the cursor inside "" at the beginning
and I press tab I get the option to choose helper.R. So Im guessing
that I'm on the right directory.
Any ideas what I'm missing?

I'm stuck on this lines of code 2 days now.
I would really appreciate
any ideas.


Thanks in advance for your help!!!


ps. I tried all the combinations in Tools->Global Options-> "Evaluate
chunks in directory" with no luck.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: rmarkdown and source call to R file.

Jeff Newmiller
This is off topic here... please read the Posting Guide about getting help on contributed packages.  Check out the RStudio forums.

FWIW you should also look carefully at ?knitr::knit_global ... I don't think it does what you seem to think it does.

On January 21, 2021 10:49:17 PM PST, Georgios via R-help <[hidden email]> wrote:

>Hi!
>I'm new in R and this list.
>I made a shiny app using R studio.
>my files are:
>   -server.R
>   -ui.R
>   -helper.R
>   -Report.Rmd.
>
>All the files are on the same directory and helper.R is a file that
>contains a lot of functions used in Report.Rmd and server.R
>
>for some reason I cant call from Report.Rmd the file helper.R
>
>My code in Report.Rmd is
>
>   ## Summarize table
>   ```{r, echo=FALSE}
>   library(knitr)
>   source("helper.R", local = knitr::knit_global())
>   summarized_table<-give_table(params$ldf_summary)
>   kable(summarized_table,"simple")
>   ```
>If I use absolute path it works but since I want to upload it to
>https://www.shinyapps.io/ I must make it work with relative path.
>
>The message I get is:
>
>   processing file: Report.Rmd
>    
>   |..........................                                        
>                                        |  25%
>     ordinary text without R code
>
>    
>   |....................................................              
>                                        |  50%
>   label: unnamed-chunk-1 (with options)
>   List of 1
>    $ echo: logi FALSE
>
>   Quitting from lines 13-17 (Report.Rmd)
>
>   Warning: Error in file: cannot open the connection
>     [No stack trace available]
>
>
>The funny thing is that if I put the cursor inside "" at the beginning
>and I press tab I get the option to choose helper.R. So Im guessing
>that I'm on the right directory.
>Any ideas what I'm missing?
>
>I'm stuck on this lines of code 2 days now.
>I would really appreciate
>any ideas.
>
>
>Thanks in advance for your help!!!
>
>
>ps. I tried all the combinations in Tools->Global Options-> "Evaluate
>chunks in directory" with no luck.
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: rmarkdown and source call to R file.

John Kane-3
In reply to this post by R help mailing list-2
You would be better to try https://community.rstudio.com. Shiny is
basically Tidyverse/Rstudio item and there will be a lot more expertise
there.

On Fri, 22 Jan 2021 at 02:02, Georgios via R-help <[hidden email]>
wrote:

> Hi!
> I'm new in R and this list.
> I made a shiny app using R studio.
> my files are:
>    -server.R
>    -ui.R
>    -helper.R
>    -Report.Rmd.
>
> All the files are on the same directory and helper.R is a file that
> contains a lot of functions used in Report.Rmd and server.R
>
> for some reason I cant call from Report.Rmd the file helper.R
>
> My code in Report.Rmd is
>
>    ## Summarize table
>    ```{r, echo=FALSE}
>    library(knitr)
>    source("helper.R", local = knitr::knit_global())
>    summarized_table<-give_table(params$ldf_summary)
>    kable(summarized_table,"simple")
>    ```
> If I use absolute path it works but since I want to upload it to
> https://www.shinyapps.io/ I must make it work with relative path.
>
> The message I get is:
>
>    processing file: Report.Rmd
>
>    |..........................
>                                         |  25%
>      ordinary text without R code
>
>
>    |....................................................
>                                         |  50%
>    label: unnamed-chunk-1 (with options)
>    List of 1
>     $ echo: logi FALSE
>
>    Quitting from lines 13-17 (Report.Rmd)
>
>    Warning: Error in file: cannot open the connection
>      [No stack trace available]
>
>
> The funny thing is that if I put the cursor inside "" at the beginning
> and I press tab I get the option to choose helper.R. So Im guessing
> that I'm on the right directory.
> Any ideas what I'm missing?
>
> I'm stuck on this lines of code 2 days now.
> I would really appreciate
> any ideas.
>
>
> Thanks in advance for your help!!!
>
>
> ps. I tried all the combinations in Tools->Global Options-> "Evaluate
> chunks in directory" with no luck.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
John Kane
Kingston ON Canada

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: rmarkdown and source call to R file.

Yihui Xie-2
In reply to this post by R help mailing list-2
I don't know the answer (there are multiple possible reasons for the
file not being found), but as the first step to debug the problem, you
may replace this chunk

```{r, echo=FALSE}
   library(knitr)
   source("helper.R", local = knitr::knit_global())
   summarized_table<-give_table(params$ldf_summary)
   kable(summarized_table,"simple")
```

with

```{r}
getwd()
list.files()
```

and see what the working directory is, and which files are available.

Regards,
Yihui


On Fri, Jan 22, 2021 at 1:02 AM Georgios via R-help
<[hidden email]> wrote:

>
> Hi!
> I'm new in R and this list.
> I made a shiny app using R studio.
> my files are:
>    -server.R
>    -ui.R
>    -helper.R
>    -Report.Rmd.
>
> All the files are on the same directory and helper.R is a file that
> contains a lot of functions used in Report.Rmd and server.R
>
> for some reason I cant call from Report.Rmd the file helper.R
>
> My code in Report.Rmd is
>
>    ## Summarize table
>    ```{r, echo=FALSE}
>    library(knitr)
>    source("helper.R", local = knitr::knit_global())
>    summarized_table<-give_table(params$ldf_summary)
>    kable(summarized_table,"simple")
>    ```
> If I use absolute path it works but since I want to upload it to
> https://www.shinyapps.io/ I must make it work with relative path.
>
> The message I get is:
>
>    processing file: Report.Rmd
>
>    |..........................
>                                         |  25%
>      ordinary text without R code
>
>
>    |....................................................
>                                         |  50%
>    label: unnamed-chunk-1 (with options)
>    List of 1
>     $ echo: logi FALSE
>
>    Quitting from lines 13-17 (Report.Rmd)
>
>    Warning: Error in file: cannot open the connection
>      [No stack trace available]
>
>
> The funny thing is that if I put the cursor inside "" at the beginning
> and I press tab I get the option to choose helper.R. So Im guessing
> that I'm on the right directory.
> Any ideas what I'm missing?
>
> I'm stuck on this lines of code 2 days now.
> I would really appreciate
> any ideas.
>
>
> Thanks in advance for your help!!!
>
>
> ps. I tried all the combinations in Tools->Global Options-> "Evaluate
> chunks in directory" with no luck.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: rmarkdown and source call to R file.

R help mailing list-2
Thanks all of you for your answers.
I managed to solve it after all. I was looking at the wrong place. It
was an argument on the server.R.

On Fri, 2021-01-22 at 09:17 -0600, Yihui Xie wrote:

> I don't know the answer (there are multiple possible reasons for the
> file not being found), but as the first step to debug the problem,
> you
> may replace this chunk
>
> ```{r, echo=FALSE}
>    library(knitr)
>    source("helper.R", local = knitr::knit_global())
>    summarized_table<-give_table(params$ldf_summary)
>    kable(summarized_table,"simple")
> ```
>
> with
>
> ```{r}
> getwd()
> list.files()
> ```
>
> and see what the working directory is, and which files are available.
>
> Regards,
> Yihui
>
>
> On Fri, Jan 22, 2021 at 1:02 AM Georgios via R-help
> <[hidden email]> wrote:
> > Hi!
> > I'm new in R and this list.
> > I made a shiny app using R studio.
> > my files are:
> >    -server.R
> >    -ui.R
> >    -helper.R
> >    -Report.Rmd.
> >
> > All the files are on the same directory and helper.R is a file that
> > contains a lot of functions used in Report.Rmd and server.R
> >
> > for some reason I cant call from Report.Rmd the file helper.R
> >
> > My code in Report.Rmd is
> >
> >    ## Summarize table
> >    ```{r, echo=FALSE}
> >    library(knitr)
> >    source("helper.R", local = knitr::knit_global())
> >    summarized_table<-give_table(params$ldf_summary)
> >    kable(summarized_table,"simple")
> >    ```
> > If I use absolute path it works but since I want to upload it to
> > https://www.shinyapps.io/ I must make it work with relative path.
> >
> > The message I get is:
> >
> >    processing file: Report.Rmd
> >
> >    |..........................
> >                                         |  25%
> >      ordinary text without R code
> >
> >
> >    |....................................................
> >                                         |  50%
> >    label: unnamed-chunk-1 (with options)
> >    List of 1
> >     $ echo: logi FALSE
> >
> >    Quitting from lines 13-17 (Report.Rmd)
> >
> >    Warning: Error in file: cannot open the connection
> >      [No stack trace available]
> >
> >
> > The funny thing is that if I put the cursor inside "" at the
> > beginning
> > and I press tab I get the option to choose helper.R. So Im guessing
> > that I'm on the right directory.
> > Any ideas what I'm missing?
> >
> > I'm stuck on this lines of code 2 days now.
> > I would really appreciate
> > any ideas.
> >
> >
> > Thanks in advance for your help!!!
> >
> >
> > ps. I tried all the combinations in Tools->Global Options->
> > "Evaluate
> > chunks in directory" with no luck.
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.