Strange message after reading multiple scripts from one folder

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

Strange message after reading multiple scripts from one folder

Frank S.
Dear list,
 
I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
I can read them properly by doing:
 
> pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes", full.names = TRUE)
> sapply(pathnames, USE.NAMES = FALSE, FUN = source,)
 
However, R generates the following message:
 
        [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
value   ?     ?     ?     ?     ?     ?     ?     ?     ?     ?        
visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 
What does it mean and what should I change to avoid this message?
Any help would be appreciated!
 
Best,
 
Frank

     
        [[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: Strange message after reading multiple scripts from one folder

jholtman
Hard to tell without seeing the scripts.  Do you have a matrix in your
scripts that have "value" and "visible" as row names?  You probably have
some statement that is causing output and so the problem is "your" as to
how to avoid the message.  So look at your scripts to see if anything
refers to either "value" or "visible", and then you might find the cause of
your problem.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Fri, Jul 29, 2016 at 6:52 AM, Frank S. <[hidden email]> wrote:

> Dear list,
>
> I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
> I can read them properly by doing:
>
> > pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes",
> full.names = TRUE)
> > sapply(pathnames, USE.NAMES = FALSE, FUN = source,)
>
> However, R generates the following message:
>
>         [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
> value   ?     ?     ?     ?     ?     ?     ?     ?     ?     ?
> visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
> What does it mean and what should I change to avoid this message?
> Any help would be appreciated!
>
> Best,
>
> Frank
>
>
>         [[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.
>

        [[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: Strange message after reading multiple scripts from one folder

Fox, John
In reply to this post by Frank S.
Dear Frank,

What you see isn't a "message" but the result returned by sapply(). The ?s indicate that sapply() didn't know what to do with the corresponding element. In an individual use of source(), the result, a 2-element list, is returned invisibly, so you don't see it.

To see what's going on, try

res <- lapply(pathnames, FUN = source)
str(res)

I hope this helps,
 John

-----------------------------
John Fox, Professor
McMaster University
Hamilton, Ontario
Canada L8S 4M4
Web: socserv.mcmaster.ca/jfox



> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Frank S.
> Sent: July 29, 2016 6:52 AM
> To: [hidden email]
> Subject: [R] Strange message after reading multiple scripts from one folder
>
> Dear list,
>
> I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
> I can read them properly by doing:
>
> > pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes",
> > full.names = TRUE) sapply(pathnames, USE.NAMES = FALSE, FUN = source,)
>
> However, R generates the following message:
>
>         [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
> value   ?     ?     ?     ?     ?     ?     ?     ?     ?     ?
> visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
> What does it mean and what should I change to avoid this message?
> Any help would be appreciated!
>
> Best,
>
> Frank
>
>
> [[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.

______________________________________________
[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: Strange message after reading multiple scripts from one folder

Keith Jewell-2
In reply to this post by jholtman
I can't immediately see it in the help text but it seems that source
returns a list with two named elements; value and visible.

I surmise that it is returned using withVisible (qv).

KJ

On 29/07/2016 13:26, jim holtman wrote:

> Hard to tell without seeing the scripts.  Do you have a matrix in your
> scripts that have "value" and "visible" as row names?  You probably have
> some statement that is causing output and so the problem is "your" as to
> how to avoid the message.  So look at your scripts to see if anything
> refers to either "value" or "visible", and then you might find the cause of
> your problem.
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> On Fri, Jul 29, 2016 at 6:52 AM, Frank S. <[hidden email]> wrote:
>
>> Dear list,
>>
>> I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
>> I can read them properly by doing:
>>
>>> pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes",
>> full.names = TRUE)
>>> sapply(pathnames, USE.NAMES = FALSE, FUN = source,)
>>
>> However, R generates the following message:
>>
>>          [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
>> value   ?     ?     ?     ?     ?     ?     ?     ?     ?     ?
>> visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>>
>> What does it mean and what should I change to avoid this message?
>> Any help would be appreciated!
>>
>> Best,
>>
>> Frank
>>
>>
>>          [[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.
>>
>
> [[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: Strange message after reading multiple scripts from one folder

MacQueen, Don
In reply to this post by Frank S.
For what it's worth (perhaps little...), I would normally do

for (pn in pathnames) source(pn)

It's clearer to read and won't return a strange value. I doubt there will
be a noticeable difference in speed. It can easily be extended to be more
informative, as in
for (pn in pathnames) {
  cat('--- now sourcing',pn,'---\n')
  source(pn)
}

One could also introduce error trapping using try() in this version.

As far as surpassing the message is concerned, one option would be to put
your sapply() expression inside invisible(). Not sure what will happen in
that case if any of the scripts fail with an error.

> 10*2
[1] 20
> invisible(10*2)

>

-Don

--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 7/29/16, 3:52 AM, "R-help on behalf of Frank S."
<[hidden email] on behalf of [hidden email]> wrote:

>Dear list,
>
>I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
>I can read them properly by doing:
>
>> pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes",
>>full.names = TRUE)
>> sapply(pathnames, USE.NAMES = FALSE, FUN = source,)
>
>However, R generates the following message:
>
>        [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
>value   ?     ?     ?     ?     ?     ?     ?     ?     ?     ?
>visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
>What does it mean and what should I change to avoid this message?
>Any help would be appreciated!
>
>Best,
>
>Frank
>
>    
> [[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.

______________________________________________
[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: Strange message after reading multiple scripts from one folder

Frank S.
Dear Keith, Jim, John and Don:
 
Thanks a bunch for your quick replies! They have helped me a lot in order to understand the problem I had in the code. As all of you pointed out, the root of problem consisted in having a list with two named elements. Furthermore, it is very interesting the use of invisible() statement. In particular, the solutions proposed by John Fox and Don MacQueen work correctly.
 
Thank you very much!!
 
Sincerely,
 
Frank S.
 

> From: [hidden email]
> To: [hidden email]; [hidden email]
> Subject: Re: [R] Strange message after reading multiple scripts from one folder
> Date: Fri, 29 Jul 2016 15:54:20 +0000
>
> For what it's worth (perhaps little...), I would normally do
>
> for (pn in pathnames) source(pn)
>
> It's clearer to read and won't return a strange value. I doubt there will
> be a noticeable difference in speed. It can easily be extended to be more
> informative, as in
> for (pn in pathnames) {
>   cat('--- now sourcing',pn,'---\n')
>   source(pn)
> }
>
> One could also introduce error trapping using try() in this version.
>
> As far as surpassing the message is concerned, one option would be to put
> your sapply() expression inside invisible(). Not sure what will happen in
> that case if any of the scripts fail with an error.
>
> > 10*2
> [1] 20
> > invisible(10*2)
>
> >
>
> -Don
>
> --
> Don MacQueen
>
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
>
>
>
>
>
> On 7/29/16, 3:52 AM, "R-help on behalf of Frank S."
> <[hidden email] on behalf of [hidden email]> wrote:
>
> >Dear list,
> >
> >I have one folder named "scripts_JMbayes", wich contains 10 R scripts.
> >I can read them properly by doing:
> >
> >> pathnames <- list.files(pattern="[.]R", path="Mydir/scripts_JMbayes",
> >>full.names = TRUE)
> >> sapply(pathnames, USE.NAMES = FALSE, FUN = source,)
> >
> >However, R generates the following message:
> >
> >        [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9]  [,10]
> >value   ?     ?     ?     ?     ?     ?     ?     ?     ?     ?
> >visible FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> >
> >What does it mean and what should I change to avoid this message?
> >Any help would be appreciated!
> >
> >Best,
> >
> >Frank
> >
> >    
> > [[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.
>
     
        [[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.