Quantcast

help with gradient boxplot

Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

help with gradient boxplot

Fix Ace
Hello, there,
I will like to fill the boxplot with gradient color, as exampled below:

Can anyone help me figure out what package I should go with?
Thank you very much for any inputs!
Kind regards,
Ace

______________________________________________
[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.

image.png (96K) Download Attachment
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] help with gradient boxplot

Paul Murrell-2
Hi

'gridSVG' might be one way to get this.  For example ...

library(lattice)
# Draw boxplot (with a package that sits on top of 'grid')
bwplot(voice.part ~ height, data=singer, xlab="Height (inches)",
        horizontal=FALSE)

library(grid)
grid.ls()
# Looks like boxes are called <blah>bwplot.box.polygon<blah>

library(gridSVG)
# Define linear gradient
fill <- linearGradient(c("blue", "red"),
                        x0=.5, x1=.5,
                        gradientUnits="coords")
# Register gradient now so it applies to the whole page
registerGradientFill("br", fill)
# Fill each box with gradient
grid.gradientFill("bwplot.box.polygon", label=rep("br", 17), grep=TRUE,
                   group=FALSE)
# Generate SVG version "Rplots.svg"
# (where the gradient will actually be visible)
grid.export()

Does that help ?

Paul

On 07/12/16 09:14, Fix Ace wrote:

> Hello, there,
> I will like to fill the boxplot with gradient color, as exampled below:
>
> Can anyone help me figure out what package I should go with?
> Thank you very much for any inputs!
> Kind regards,
> Ace
>
>
>
> ______________________________________________
> [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.
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] help with gradient boxplot

R help mailing list-2
Hi, Paul,
Thank you very much for your reply. I tried your sample code, but did not get gradient filling (still empty box). And many warnings:1: In checkAttrs(attrs, eltName) :
  Removing non-SVG attribute name(s): fill, fill-opacity
2: In checkAttrs(attrs, eltName) :
  Removing non-SVG attribute name(s): fill, fill-opacity
3: In checkAttrs(attrs, eltName) :
  Removing non-SVG attribute name(s): fill, fill-opacity
4: In checkAttrs(attrs, eltName) :
  Removing non-SVG attribute name(s): fill, fill-opacity
5: In checkAttrs(attrs, eltName) :
...

I saw the figure in an article, and so I don't have to script. I am actually trying to generate the similar figure for my own data.

Any other thoughts?
Thanks.
Ace
 

    On Tuesday, December 6, 2016 7:43 PM, Paul Murrell <[hidden email]> wrote:
 

 Hi

'gridSVG' might be one way to get this.  For example ...

library(lattice)
# Draw boxplot (with a package that sits on top of 'grid')
bwplot(voice.part ~ height, data=singer, xlab="Height (inches)",
        horizontal=FALSE)

library(grid)
grid.ls()
# Looks like boxes are called <blah>bwplot.box.polygon<blah>

library(gridSVG)
# Define linear gradient
fill <- linearGradient(c("blue", "red"),
                        x0=.5, x1=.5,
                        gradientUnits="coords")
# Register gradient now so it applies to the whole page
registerGradientFill("br", fill)
# Fill each box with gradient
grid.gradientFill("bwplot.box.polygon", label=rep("br", 17), grep=TRUE,
                  group=FALSE)
# Generate SVG version "Rplots.svg"
# (where the gradient will actually be visible)
grid.export()

Does that help ?

Paul

On 07/12/16 09:14, Fix Ace wrote:

> Hello, there,
> I will like to fill the boxplot with gradient color, as exampled below:
>
> Can anyone help me figure out what package I should go with?
> Thank you very much for any inputs!
> Kind regards,
> Ace
>
>
>
> ______________________________________________
> [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.
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/


   
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] help with gradient boxplot

Paul Murrell-2
Hi

You could try ...

grid.export(..., strict=FALSE)

... and/or install the latest gridSVG version from R-Forge ...

https://r-forge.r-project.org/R/?group_id=1025

Paul

On 09/12/16 11:13, Fix Ace wrote:

> Hi, Paul,
>
> Thank you very much for your reply. I tried your sample code, but did
> not get gradient filling (still empty box). And many warnings:
> 1: In checkAttrs(attrs, eltName) :
>   Removing non-SVG attribute name(s): fill, fill-opacity
> 2: In checkAttrs(attrs, eltName) :
>   Removing non-SVG attribute name(s): fill, fill-opacity
> 3: In checkAttrs(attrs, eltName) :
>   Removing non-SVG attribute name(s): fill, fill-opacity
> 4: In checkAttrs(attrs, eltName) :
>   Removing non-SVG attribute name(s): fill, fill-opacity
> 5: In checkAttrs(attrs, eltName) :
> .
> .
> .
>
> I saw the figure in an article, and so I don't have to script. I am
> actually trying to generate the similar figure for my own data.
>
> Any other thoughts?
>
> Thanks.
>
> Ace
>
>
> On Tuesday, December 6, 2016 7:43 PM, Paul Murrell
> <[hidden email]> wrote:
>
>
> Hi
>
> 'gridSVG' might be one way to get this.  For example ...
>
> library(lattice)
> # Draw boxplot (with a package that sits on top of 'grid')
> bwplot(voice.part ~ height, data=singer, xlab="Height (inches)",
>         horizontal=FALSE)
>
> library(grid)
> grid.ls()
> # Looks like boxes are called <blah>bwplot.box.polygon<blah>
>
> library(gridSVG)
> # Define linear gradient
> fill <- linearGradient(c("blue", "red"),
>                         x0=.5, x1=.5,
>                         gradientUnits="coords")
> # Register gradient now so it applies to the whole page
> registerGradientFill("br", fill)
> # Fill each box with gradient
> grid.gradientFill("bwplot.box.polygon", label=rep("br", 17), grep=TRUE,
>                   group=FALSE)
> # Generate SVG version "Rplots.svg"
> # (where the gradient will actually be visible)
> grid.export()
>
> Does that help ?
>
> Paul
>
> On 07/12/16 09:14, Fix Ace wrote:
>> Hello, there,
>> I will like to fill the boxplot with gradient color, as exampled below:
>>
>> Can anyone help me figure out what package I should go with?
>> Thank you very much for any inputs!
>> Kind regards,
>> Ace
>
>>
>>
>>
>> ______________________________________________
>> [hidden email] <mailto:[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
> <http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> [hidden email] <mailto:[hidden email]>
> http://www.stat.auckland.ac.nz/~paul/
>
>
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] help with gradient boxplot

R help mailing list-2
Hi, Paul,
Thank you very much! It works this time with "strict=FALSE" option.
Another relevant question:
how did you figure out  that boxes in boxplot are called "bwplot.box.polygon". If I am trying to make a gradient filling for barplot of other plots, how would I define grobs?
Thanks!!
Ace



 

    On Thursday, December 8, 2016 5:24 PM, Paul Murrell <[hidden email]> wrote:
 

 Hi

You could try ...

grid.export(..., strict=FALSE)

... and/or install the latest gridSVG version from R-Forge ...

https://r-forge.r-project.org/R/?group_id=1025

Paul


   
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] help with gradient boxplot

Paul Murrell-2
Hi

Great to hear you have it working.

Figuring out the names of grobs takes two things:

1. someone has to name the grobs
2. grid.ls()

The reason why I did my example using 'lattice' is because 'lattice'
names all of its grobs.  There is a document ...

http://lattice.r-forge.r-project.org/Vignettes/src/naming-scheme/namingScheme.pdf

... that describes the 'lattice' naming scheme.

Paul

On 10/12/16 10:39, Fix Ace wrote:

> Hi, Paul,
>
> Thank you very much! It works this time with "strict=FALSE" option.
>
> Another relevant question:
>
> how did you figure out  that boxes in boxplot are called
> "bwplot.box.polygon". If I am trying to make a gradient filling for
> barplot of other plots, how would I define grobs?
>
> Thanks!!
>
> Ace
>
>
>
>
>
> On Thursday, December 8, 2016 5:24 PM, Paul Murrell
> <[hidden email]> wrote:
>
>
> Hi
>
> You could try ...
>
> grid.export(..., strict=FALSE)
>
> ... and/or install the latest gridSVG version from R-Forge ...
>
> https://r-forge.r-project.org/R/?group_id=1025
>
> Paul
>
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] help with gradient boxplot

R help mailing list-2
Hi, Paul,
Thank you so much for this further clarification!
Ace

    On Sunday, December 11, 2016 2:09 PM, Paul Murrell <[hidden email]> wrote:
 

 Hi

Great to hear you have it working.

Figuring out the names of grobs takes two things:

1. someone has to name the grobs
2. grid.ls()

The reason why I did my example using 'lattice' is because 'lattice'
names all of its grobs.  There is a document ...

http://lattice.r-forge.r-project.org/Vignettes/src/naming-scheme/namingScheme.pdf

... that describes the 'lattice' naming scheme.

Paul

On 10/12/16 10:39, Fix Ace wrote:

> Hi, Paul,
>
> Thank you very much! It works this time with "strict=FALSE" option.
>
> Another relevant question:
>
> how did you figure out  that boxes in boxplot are called
> "bwplot.box.polygon". If I am trying to make a gradient filling for
> barplot of other plots, how would I define grobs?
>
> Thanks!!
>
> Ace
>
>
>
>
>
> On Thursday, December 8, 2016 5:24 PM, Paul Murrell
> <[hidden email]> wrote:
>
>
> Hi
>
> You could try ...
>
> grid.export(..., strict=FALSE)
>
> ... and/or install the latest gridSVG version from R-Forge ...
>
> https://r-forge.r-project.org/R/?group_id=1025
>
> Paul
>
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/


   
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

princomp() output loadings component missing

R help mailing list-2
In reply to this post by Fix Ace
Hello, there,
I did a test run for this princomp() function using USArrests data. The R document says that the output loadings contain the eigenvector matrix. When I looked at this matrix, I found that a missing item for Comp.4

   > p3=princomp(USArrests, cor=TRUE )> p3$loadings
Loadings:         Comp.1 Comp.2 Comp.3 Comp.4Murder   -0.536  0.418 -0.341  0.649Assault  -0.583  0.188 -0.268 -0.743UrbanPop -0.278 -0.873 -0.378  0.134Rape     -0.543 -0.167  0.818       
               Comp.1 Comp.2 Comp.3 Comp.4SS loadings      1.00   1.00   1.00   1.00Proportion Var   0.25   0.25   0.25   0.25Cumulative Var   0.25   0.50   0.75   1.00
How should I explain this?
Thanks.
Ace

   
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: princomp() output loadings component missing

Ben Tupper-2
Hi,

Check out the detailed explanation in the 'Value' section of ?princomp - in particular for 'loadings'.  It will send you to ?loadings where it explains why that one element appears to be missing.

If you really want to see the missing value try...

p3$loadings['Rape', 'Comp.4']

... or even ...

unclass(p3$loadings)

Don't forget that this email list works best when messages are send in plain text, and it works poorly for html or rich text.  Check the settings in your email client.  In case others are interested here is what the loadings print to...

Loadings:
         Comp.1 Comp.2 Comp.3 Comp.4
Murder   -0.536  0.418 -0.341  0.649
Assault  -0.583  0.188 -0.268 -0.743
UrbanPop -0.278 -0.873 -0.378  0.134
Rape     -0.543 -0.167  0.818      

               Comp.1 Comp.2 Comp.3 Comp.4
SS loadings      1.00   1.00   1.00   1.00
Proportion Var   0.25   0.25   0.25   0.25
Cumulative Var   0.25   0.50   0.75   1.00

Cheers,
Ben

> On Jan 29, 2017, at 4:31 AM, Fix Ace via R-help <[hidden email]> wrote:
>
> Hello, there,
> I did a test run for this princomp() function using USArrests data. The R document says that the output loadings contain the eigenvector matrix. When I looked at this matrix, I found that a missing item for Comp.4
>
>> p3=princomp(USArrests, cor=TRUE )> p3$loadings
> Loadings:         Comp.1 Comp.2 Comp.3 Comp.4Murder   -0.536  0.418 -0.341  0.649Assault  -0.583  0.188 -0.268 -0.743UrbanPop -0.278 -0.873 -0.378  0.134Rape     -0.543 -0.167  0.818      
>                Comp.1 Comp.2 Comp.3 Comp.4SS loadings      1.00   1.00   1.00   1.00Proportion Var   0.25   0.25   0.25   0.25Cumulative Var   0.25   0.50   0.75   1.00
> How should I explain this?
> Thanks.
> Ace
>
>
> [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: princomp() output loadings component missing

R help mailing list-2
Thank you very much!
Ace

    On Sunday, January 29, 2017 4:13 PM, Ben Tupper <[hidden email]> wrote:
 

 Hi,

Check out the detailed explanation in the 'Value' section of ?princomp - in particular for 'loadings'.  It will send you to ?loadings where it explains why that one element appears to be missing.

If you really want to see the missing value try...

p3$loadings['Rape', 'Comp.4']

... or even ...

unclass(p3$loadings)

Don't forget that this email list works best when messages are send in plain text, and it works poorly for html or rich text.  Check the settings in your email client.  In case others are interested here is what the loadings print to...

Loadings:
        Comp.1 Comp.2 Comp.3 Comp.4
Murder  -0.536  0.418 -0.341  0.649
Assault  -0.583  0.188 -0.268 -0.743
UrbanPop -0.278 -0.873 -0.378  0.134
Rape    -0.543 -0.167  0.818     

              Comp.1 Comp.2 Comp.3 Comp.4
SS loadings      1.00  1.00  1.00  1.00
Proportion Var  0.25  0.25  0.25  0.25
Cumulative Var  0.25  0.50  0.75  1.00

Cheers,
Ben

> On Jan 29, 2017, at 4:31 AM, Fix Ace via R-help <[hidden email]> wrote:
>
> Hello, there,
> I did a test run for this princomp() function using USArrests data. The R document says that the output loadings contain the eigenvector matrix. When I looked at this matrix, I found that a missing item for Comp.4
>
>> p3=princomp(USArrests, cor=TRUE )> p3$loadings
> Loadings:        Comp.1 Comp.2 Comp.3 Comp.4Murder  -0.536  0.418 -0.341  0.649Assault  -0.583  0.188 -0.268 -0.743UrbanPop -0.278 -0.873 -0.378  0.134Rape    -0.543 -0.167  0.818     
>                Comp.1 Comp.2 Comp.3 Comp.4SS loadings      1.00  1.00  1.00  1.00Proportion Var  0.25  0.25  0.25  0.25Cumulative Var  0.25  0.50  0.75  1.00
> How should I explain this?
> Thanks.
> Ace
>
>
>     [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org




   
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

get() return nothing

R help mailing list-2
In reply to this post by R help mailing list-2
Hello, there,
I wrote a loop to check the dimension of all the .txt dataframes:> ls()
 [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
 [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
 [9] "galnt6"          "galnt6.txt"      "glyco"           "glyco.txt"
[13] "i"               "mtscaled"        "newsig.table"    "nicepca"
[17] "pca"             "sig.txt"         "st3gal3"         "st3gal3.txt"
[21] "st3gal5"         "st3gal5.txt"     "st6gal1"         "st6gal1.txt"
> for(i in ls(pattern="txt")){dim(get(i))}
>
If I check individual ones, they are ok:
> dim(get("galnt4.txt"))
[1] 8 3
>
could anyone help me to figure out why it did not work with a loop?
Thanks a lot!

Ace






 

 
 
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: get() return nothing

Duncan Murdoch-2
On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:

> Hello, there,
> I wrote a loop to check the dimension of all the .txt dataframes:> ls()
>  [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
>  [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
>  [9] "galnt6"          "galnt6.txt"      "glyco"           "glyco.txt"
> [13] "i"               "mtscaled"        "newsig.table"    "nicepca"
> [17] "pca"             "sig.txt"         "st3gal3"         "st3gal3.txt"
> [21] "st3gal5"         "st3gal5.txt"     "st6gal1"         "st6gal1.txt"
>> for(i in ls(pattern="txt")){dim(get(i))}
>>
> If I check individual ones, they are ok:
>> dim(get("galnt4.txt"))
> [1] 8 3
>>
> could anyone help me to figure out why it did not work with a loop?
> Thanks a lot!

It's the difference between

for (i in 1:10) i

(which prints nothing) and

for (i in 1:10) print(i)

Duncan Murdoch

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: get() return nothing

R help mailing list-2
Well, I am not trying to print anything. I just would like to get the dimension information for all the dataframes I created. Could you please help me to develop the script?
Thanks.
Ace

    On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch <[hidden email]> wrote:
 

 On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:

> Hello, there,
> I wrote a loop to check the dimension of all the .txt dataframes:> ls()
>  [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
>  [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
>  [9] "galnt6"          "galnt6.txt"      "glyco"          "glyco.txt"
> [13] "i"              "mtscaled"        "newsig.table"    "nicepca"
> [17] "pca"            "sig.txt"        "st3gal3"        "st3gal3.txt"
> [21] "st3gal5"        "st3gal5.txt"    "st6gal1"        "st6gal1.txt"
>> for(i in ls(pattern="txt")){dim(get(i))}
>>
> If I check individual ones, they are ok:
>> dim(get("galnt4.txt"))
> [1] 8 3
>>
> could anyone help me to figure out why it did not work with a loop?
> Thanks a lot!

It's the difference between

for (i in 1:10) i

(which prints nothing) and

for (i in 1:10) print(i)

Duncan Murdoch



   
        [[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: get() return nothing

David Winsemius

> On Feb 13, 2017, at 8:50 AM, Fix Ace via R-help <[hidden email]> wrote:
>
> Well, I am not trying to print anything. I just would like to get the dimension information for all the dataframes I created. Could you please help me to develop the script?

You should post R code that builds objects of similar structure as your use case.
(
At the moment we don't know how these dataframes are assembled (in a list?) or having names with a structure that we need to get() or with an associated character vector with their names that are not R names.)

--
David.

> Thanks.
> Ace
>
>    On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch <[hidden email]> wrote:
>
>
> On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:
>> Hello, there,
>> I wrote a loop to check the dimension of all the .txt dataframes:> ls()
>>   [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
>>   [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
>>   [9] "galnt6"          "galnt6.txt"      "glyco"          "glyco.txt"
>> [13] "i"              "mtscaled"        "newsig.table"    "nicepca"
>> [17] "pca"            "sig.txt"        "st3gal3"        "st3gal3.txt"
>> [21] "st3gal5"        "st3gal5.txt"    "st6gal1"        "st6gal1.txt"
>>> for(i in ls(pattern="txt")){dim(get(i))}
>>>
>> If I check individual ones, they are ok:
>>> dim(get("galnt4.txt"))
>> [1] 8 3
>>>
>> could anyone help me to figure out why it did not work with a loop?
>> Thanks a lot!
>
> It's the difference between
>
> for (i in 1:10) i
>
> (which prints nothing) and
>
> for (i in 1:10) print(i)
>
> Duncan Murdoch
>
>
>
>
> [[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.

David Winsemius
Alameda, CA, USA

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] Re: get() return nothing

Rolf Turner
In reply to this post by R help mailing list-2

On 14/02/17 05:50, Fix Ace via R-help wrote:

> Well, I am not trying to print anything. I just would like to get the dimension information for all the dataframes I created. Could you please help me to develop the script?
> Thanks.
> Ace

Yes you *are* trying to print something.  You are trying to print the
dimension information, i.e. dim(get(i))!!! For Pete's sake (a) *think*
about what you are doing and (b) *try* example that Duncan suggested to you.

cheers,

Rolf Turner

>
>     On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch <[hidden email]> wrote:
>
>
>  On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:
>> Hello, there,
>> I wrote a loop to check the dimension of all the .txt dataframes:> ls()
>>   [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
>>   [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
>>   [9] "galnt6"          "galnt6.txt"      "glyco"          "glyco.txt"
>> [13] "i"              "mtscaled"        "newsig.table"    "nicepca"
>> [17] "pca"            "sig.txt"        "st3gal3"        "st3gal3.txt"
>> [21] "st3gal5"        "st3gal5.txt"    "st6gal1"        "st6gal1.txt"
>>> for(i in ls(pattern="txt")){dim(get(i))}
>>>
>> If I check individual ones, they are ok:
>>> dim(get("galnt4.txt"))
>> [1] 8 3
>>>
>> could anyone help me to figure out why it did not work with a loop?
>> Thanks a lot!
>
> It's the difference between
>
> for (i in 1:10) i
>
> (which prints nothing) and
>
> for (i in 1:10) print(i)
>
> Duncan Murdoch
>
>
>
>
> [[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.
>


--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] Re: get() return nothing

Ben Tupper-2
Hi,

When you want to get 'something' out of a loop you need to assign that 'something' to a variable that persists outside of the loop. I think it is a scoping thing. In your situation you could create a list with as many elements as there are objects with 'txt' in their names.  I can't quite follow what is is you are after, but perhaps something like this (untested and I'm still on my first cup of coffee) ...

obj_names <- ls(pattern="txt")
obj_dims <- vector(mode = 'list', length = length(obj_names))
names(obj_dims) <- obj_names
for (nm in obj_names)){
    obj_dims[[nm]] <- dim(get(nm))
}

Does that do what you want?  If so, you could probably use lapply() for the purpose instead of the for loop, but even better is to store each of your objects in a list as you create them rather than letting them get loose in the global environment.  That way you don't have to do this get-by-name rodeo to get info on them.

Cheers,
Ben



> On Feb 14, 2017, at 2:57 AM, Rolf Turner <[hidden email]> wrote:
>
>
> On 14/02/17 05:50, Fix Ace via R-help wrote:
>
>> Well, I am not trying to print anything. I just would like to get the dimension information for all the dataframes I created. Could you please help me to develop the script?
>> Thanks.
>> Ace
>
> Yes you *are* trying to print something.  You are trying to print the dimension information, i.e. dim(get(i))!!! For Pete's sake (a) *think* about what you are doing and (b) *try* example that Duncan suggested to you.
>
> cheers,
>
> Rolf Turner
>>
>>    On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch <[hidden email]> wrote:
>>
>>
>> On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:
>>> Hello, there,
>>> I wrote a loop to check the dimension of all the .txt dataframes:> ls()
>>>  [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
>>>  [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
>>>  [9] "galnt6"          "galnt6.txt"      "glyco"          "glyco.txt"
>>> [13] "i"              "mtscaled"        "newsig.table"    "nicepca"
>>> [17] "pca"            "sig.txt"        "st3gal3"        "st3gal3.txt"
>>> [21] "st3gal5"        "st3gal5.txt"    "st6gal1"        "st6gal1.txt"
>>>> for(i in ls(pattern="txt")){dim(get(i))}
>>>>
>>> If I check individual ones, they are ok:
>>>> dim(get("galnt4.txt"))
>>> [1] 8 3
>>>>
>>> could anyone help me to figure out why it did not work with a loop?
>>> Thanks a lot!
>>
>> It's the difference between
>>
>> for (i in 1:10) i
>>
>> (which prints nothing) and
>>
>> for (i in 1:10) print(i)
>>
>> Duncan Murdoch
>>
>>
>>
>>
>> [[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.
>>
>
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> [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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

______________________________________________
[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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [FORGED] Re: get() return nothing

R help mailing list-2
Thank you very much for the information! I will try it!
Ace

    On Tuesday, February 14, 2017 8:48 AM, Ben Tupper <[hidden email]> wrote:
 

 Hi,

When you want to get 'something' out of a loop you need to assign that 'something' to a variable that persists outside of the loop. I think it is a scoping thing. In your situation you could create a list with as many elements as there are objects with 'txt' in their names.  I can't quite follow what is is you are after, but perhaps something like this (untested and I'm still on my first cup of coffee) ...

obj_names <- ls(pattern="txt")
obj_dims <- vector(mode = 'list', length = length(obj_names))
names(obj_dims) <- obj_names
for (nm in obj_names)){
    obj_dims[[nm]] <- dim(get(nm))
}

Does that do what you want?  If so, you could probably use lapply() for the purpose instead of the for loop, but even better is to store each of your objects in a list as you create them rather than letting them get loose in the global environment.  That way you don't have to do this get-by-name rodeo to get info on them.

Cheers,
Ben



> On Feb 14, 2017, at 2:57 AM, Rolf Turner <[hidden email]> wrote:
>
>
> On 14/02/17 05:50, Fix Ace via R-help wrote:
>
>> Well, I am not trying to print anything. I just would like to get the dimension information for all the dataframes I created. Could you please help me to develop the script?
>> Thanks.
>> Ace
>
> Yes you *are* trying to print something.  You are trying to print the dimension information, i.e. dim(get(i))!!! For Pete's sake (a) *think* about what you are doing and (b) *try* example that Duncan suggested to you.
>
> cheers,
>
> Rolf Turner
>>
>>    On Saturday, February 11, 2017 7:53 PM, Duncan Murdoch <[hidden email]> wrote:
>>
>>
>> On 11/02/2017 1:33 PM, Fix Ace via R-help wrote:
>>> Hello, there,
>>> I wrote a loop to check the dimension of all the .txt dataframes:> ls()
>>>  [1] "actualpca.table" "b4galnt2"        "b4galnt2.txt"    "data"
>>>  [5] "galnt4"          "galnt4.txt"      "galnt5"          "galnt5.txt"
>>>  [9] "galnt6"          "galnt6.txt"      "glyco"          "glyco.txt"
>>> [13] "i"              "mtscaled"        "newsig.table"    "nicepca"
>>> [17] "pca"            "sig.txt"        "st3gal3"        "st3gal3.txt"
>>> [21] "st3gal5"        "st3gal5.txt"    "st6gal1"        "st6gal1.txt"
>>>> for(i in ls(pattern="txt")){dim(get(i))}
>>>>
>>> If I check individual ones, they are ok:
>>>> dim(get("galnt4.txt"))
>>> [1] 8 3
>>>>
>>> could anyone help me to figure out why it did not work with a loop?
>>> Thanks a lot!
>>
>> It's the difference between
>>
>> for (i in 1:10) i
>>
>> (which prints nothing) and
>>
>> for (i in 1:10) print(i)
>>
>> Duncan Murdoch
>>
>>
>>
>>
>>     [[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.
>>
>
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> [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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org




   
        [[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.
Loading...