Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Anas Jamshed
but the point is that where should I start from now

On Tue, Aug 24, 2021 at 7:43 AM Andrew Simmons  wrote:

> Hello,
>
>
> I see what you're saying that the .tar archive contains many more
> compressed files, but that's not necessarily a problem. R can read directly
> from a compressed file without having to decompress it beforehand. I
> modified my code to look a little more like yours:
>
>
> # need to do 'path.expand' or 'untar' will fail
> # this is where we put the downloaded files
> exdir <- path.expand("~/GSE162562_RAW")
> dir.create(exdir, showWarnings = FALSE)
>
>
> URL <- "
> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
> "
> FILE <- file.path(tempdir(), basename(URL))
>
>
> utils::download.file(URL, FILE, mode = "wb")
> utils::untar(FILE, exdir = exdir)
> unlink(FILE, recursive = TRUE, force = TRUE)
>
>
> # 'files' is the full path to the downloaded files
> # attribute 'names' is the basename with '.txt.gz' removed from the end
> files <- list.files(exdir, full.names = TRUE)
> names(files) <- sub("\\.txt\\.gz$", "", basename(files))
>
>
> # R can open compressed files without decompressing beforehand
> print(utils::read.table(files[[1]], sep = "\t"))
> print(utils::read.delim(files[[2]], header = FALSE))
>
>
> Does this work better than before for you?
>
> On Mon, Aug 23, 2021 at 8:16 PM Anas Jamshed 
> wrote:
>
>> sir after that I want to run:
>> #get the list of sample names
>> GSMnames <- t(list.files("~/Desktop/GSE162562_RAW", full.names = F))
>>
>> #remove .txt from file/sample names
>> GSMnames <- gsub(pattern = ".txt", replacement = "", GSMnames)
>>
>> #make a vector of the list of files to aggregate
>> files <- list.files("~/Desktop/GSE162562_RAW", full.names = TRUE)
>>
>>
>> but it is not running as after running utils::untar(FILE, exdir =
>> dirname(FILE)) it creates another 108 archieves
>>
>> On Tue, Aug 24, 2021 at 2:03 AM Andrew Simmons 
>> wrote:
>>
>>> Hello,
>>>
>>>
>>> I tried downloading that file using 'utils::download.file' (which
>>> worked), but then continued to complain about "damaged archive" when trying
>>> to use 'utils::untar'. However, it seemed to work when I downloaded the
>>> archive manually. Finally, the solution I found is that you have to specify
>>> the mode in which you're downloading the file. Something like:
>>>
>>>
>>> URL <- "
>>> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
>>> "
>>> FILE <- file.path(tempdir(), basename(URL))
>>>
>>>
>>> utils::download.file(URL, FILE, mode = "wb")
>>> utils::untar(FILE, exdir = dirname(FILE))
>>>
>>>
>>> worked perfectly for me. It seems to also work still on Ubuntu, but you
>>> can let us know if you find it doesn't. I hope this helps!
>>>
>>>
>>>
>>> On Mon, Aug 23, 2021 at 3:20 PM Anas Jamshed 
>>> wrote:
>>>
 I am trying this URL: "
 https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
 "

 but it is not giving me any file

 On Mon, Aug 23, 2021 at 11:42 PM Andrew Simmons 
 wrote:

> Hello,
>
>
> I don't think you need to use a system command directly, I think
> 'utils::untar' is all you need. I tried the same thing myself, something
> like:
>
>
> URL <- "https://exiftool.org/Image-ExifTool-12.30.tar.gz";
> FILE <- file.path(tempdir(), basename(URL))
>
>
> utils::download.file(URL, FILE)
> utils::untar(FILE, exdir = dirname(FILE))
>
>
> and it makes a folder "Image-ExifTool-12.30". It seems to work
> perfectly fine in Windows 10 x64 build 19042. Can you send the specific
> file (or provide a URL to the specific file) that isn't working for you?
>
> On Mon, Aug 23, 2021 at 12:53 PM Anas Jamshed <
> anasjamshed1...@gmail.com> wrote:
>
>> I have the file GSE162562_RAW. First I untar them
>> by untar("GSE162562_RAW.tar")
>> then I am running like:
>>  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")
>>
>>
>> This is running fine in Linux but not in windows. What changes I
>> should make to run this command in windows as well
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Andrew Simmons
Hello,


I see what you're saying that the .tar archive contains many more
compressed files, but that's not necessarily a problem. R can read directly
from a compressed file without having to decompress it beforehand. I
modified my code to look a little more like yours:


# need to do 'path.expand' or 'untar' will fail
# this is where we put the downloaded files
exdir <- path.expand("~/GSE162562_RAW")
dir.create(exdir, showWarnings = FALSE)


URL <- "
https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
"
FILE <- file.path(tempdir(), basename(URL))


utils::download.file(URL, FILE, mode = "wb")
utils::untar(FILE, exdir = exdir)
unlink(FILE, recursive = TRUE, force = TRUE)


# 'files' is the full path to the downloaded files
# attribute 'names' is the basename with '.txt.gz' removed from the end
files <- list.files(exdir, full.names = TRUE)
names(files) <- sub("\\.txt\\.gz$", "", basename(files))


# R can open compressed files without decompressing beforehand
print(utils::read.table(files[[1]], sep = "\t"))
print(utils::read.delim(files[[2]], header = FALSE))


Does this work better than before for you?

On Mon, Aug 23, 2021 at 8:16 PM Anas Jamshed 
wrote:

> sir after that I want to run:
> #get the list of sample names
> GSMnames <- t(list.files("~/Desktop/GSE162562_RAW", full.names = F))
>
> #remove .txt from file/sample names
> GSMnames <- gsub(pattern = ".txt", replacement = "", GSMnames)
>
> #make a vector of the list of files to aggregate
> files <- list.files("~/Desktop/GSE162562_RAW", full.names = TRUE)
>
>
> but it is not running as after running utils::untar(FILE, exdir =
> dirname(FILE)) it creates another 108 archieves
>
> On Tue, Aug 24, 2021 at 2:03 AM Andrew Simmons  wrote:
>
>> Hello,
>>
>>
>> I tried downloading that file using 'utils::download.file' (which
>> worked), but then continued to complain about "damaged archive" when trying
>> to use 'utils::untar'. However, it seemed to work when I downloaded the
>> archive manually. Finally, the solution I found is that you have to specify
>> the mode in which you're downloading the file. Something like:
>>
>>
>> URL <- "
>> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
>> "
>> FILE <- file.path(tempdir(), basename(URL))
>>
>>
>> utils::download.file(URL, FILE, mode = "wb")
>> utils::untar(FILE, exdir = dirname(FILE))
>>
>>
>> worked perfectly for me. It seems to also work still on Ubuntu, but you
>> can let us know if you find it doesn't. I hope this helps!
>>
>>
>>
>> On Mon, Aug 23, 2021 at 3:20 PM Anas Jamshed 
>> wrote:
>>
>>> I am trying this URL: "
>>> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
>>> "
>>>
>>> but it is not giving me any file
>>>
>>> On Mon, Aug 23, 2021 at 11:42 PM Andrew Simmons 
>>> wrote:
>>>
 Hello,


 I don't think you need to use a system command directly, I think
 'utils::untar' is all you need. I tried the same thing myself, something
 like:


 URL <- "https://exiftool.org/Image-ExifTool-12.30.tar.gz";
 FILE <- file.path(tempdir(), basename(URL))


 utils::download.file(URL, FILE)
 utils::untar(FILE, exdir = dirname(FILE))


 and it makes a folder "Image-ExifTool-12.30". It seems to work
 perfectly fine in Windows 10 x64 build 19042. Can you send the specific
 file (or provide a URL to the specific file) that isn't working for you?

 On Mon, Aug 23, 2021 at 12:53 PM Anas Jamshed <
 anasjamshed1...@gmail.com> wrote:

> I have the file GSE162562_RAW. First I untar them
> by untar("GSE162562_RAW.tar")
> then I am running like:
>  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")
>
>
> This is running fine in Linux but not in windows. What changes I
> should make to run this command in windows as well
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] data manipulation question

2021-08-23 Thread Jim Lemon
Hi Kai,
How about setting:

germlinepatients$DisclosureStatus <- NA

then having your three conditional statements as indices:

germlinepatients$DisclosureStatus[germlinepatients$gl_resultsdisclosed
== 1] <-"DISCLOSED"
germlinepatients$DisclosureStatus[germlinepatients$
gl_resultsdisclosed == 0] <- "ATTEMPTED"
 germlinepatients$DisclosureStatus[is.na(germlinepatients$gl_resultsdisclosed) &
 germlinepatients$gl_discloseattempt1 != "ATTEMPTED"] <-"ATTEMPTED"

I know it's not elegant and you could join the last two statements
with OR (|) but it may work.

Jim

On Tue, Aug 24, 2021 at 9:22 AM Kai Yang via R-help
 wrote:
>
> Hello List,
> I wrote the script below to assign value to a new field DisclosureStatus.
> my goal is if gl_resultsdisclosed=1 then DisclosureStatus=DISCLOSED
> else if gl_resultsdisclosed=0 then DisclosureStatus= ATTEMPTED
> else if gl_resultsdisclosed is missing and gl_discloseattempt1 is not missing 
> then DisclosureStatus= ATTEMPTED
> else missing
>
>
> germlinepatients$DisclosureStatus <-
>   ifelse(germlinepatients$gl_resultsdisclosed==1, "DISCLOSED",
> ifelse(germlinepatients$ gl_resultsdisclosed==0, "ATTEMPTED",
>ifelse(is.na(germlinepatients$gl_resultsdisclosed) & 
> germlinepatients$gl_discloseattempt1!='', "ATTEMPTED",
>NA)))
>
> the first 3 row give me right result, but the 3rd row does not. After 
> checking the data, there are 23 cases are gl_resultsdisclosed is missing and 
> gl_discloseattempt1 is not missing.  the code doesn't has any error message.
> Please help
> thank you
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Anas Jamshed
sir after that I want to run:
#get the list of sample names
GSMnames <- t(list.files("~/Desktop/GSE162562_RAW", full.names = F))

#remove .txt from file/sample names
GSMnames <- gsub(pattern = ".txt", replacement = "", GSMnames)

#make a vector of the list of files to aggregate
files <- list.files("~/Desktop/GSE162562_RAW", full.names = TRUE)


but it is not running as after running utils::untar(FILE, exdir =
dirname(FILE)) it creates another 108 archieves

On Tue, Aug 24, 2021 at 2:03 AM Andrew Simmons  wrote:

> Hello,
>
>
> I tried downloading that file using 'utils::download.file' (which worked),
> but then continued to complain about "damaged archive" when trying to use
> 'utils::untar'. However, it seemed to work when I downloaded the archive
> manually. Finally, the solution I found is that you have to specify the
> mode in which you're downloading the file. Something like:
>
>
> URL <- "
> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
> "
> FILE <- file.path(tempdir(), basename(URL))
>
>
> utils::download.file(URL, FILE, mode = "wb")
> utils::untar(FILE, exdir = dirname(FILE))
>
>
> worked perfectly for me. It seems to also work still on Ubuntu, but you
> can let us know if you find it doesn't. I hope this helps!
>
>
>
> On Mon, Aug 23, 2021 at 3:20 PM Anas Jamshed 
> wrote:
>
>> I am trying this URL: "
>> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
>> "
>>
>> but it is not giving me any file
>>
>> On Mon, Aug 23, 2021 at 11:42 PM Andrew Simmons 
>> wrote:
>>
>>> Hello,
>>>
>>>
>>> I don't think you need to use a system command directly, I think
>>> 'utils::untar' is all you need. I tried the same thing myself, something
>>> like:
>>>
>>>
>>> URL <- "https://exiftool.org/Image-ExifTool-12.30.tar.gz";
>>> FILE <- file.path(tempdir(), basename(URL))
>>>
>>>
>>> utils::download.file(URL, FILE)
>>> utils::untar(FILE, exdir = dirname(FILE))
>>>
>>>
>>> and it makes a folder "Image-ExifTool-12.30". It seems to work perfectly
>>> fine in Windows 10 x64 build 19042. Can you send the specific file (or
>>> provide a URL to the specific file) that isn't working for you?
>>>
>>> On Mon, Aug 23, 2021 at 12:53 PM Anas Jamshed 
>>> wrote:
>>>
 I have the file GSE162562_RAW. First I untar them
 by untar("GSE162562_RAW.tar")
 then I am running like:
  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")


 This is running fine in Linux but not in windows. What changes I
 should make to run this command in windows as well

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Dynamic Creation and Use of Object Names

2021-08-23 Thread Dr Eberhard Lisse

Thanks,

long weekend coming up :-)-O

el

On 2021-08-23 18:06 , Bert Gunter wrote:

...  and to add to Ivan's suggestions, **depending on what you are
trying to show with your grid of graphs,** you may wish to consider
using ggplot's "facet" capabilities to assure that any quantitative
variables that you are encoding in the maps (e.g. by color, density
shading, etc.)  are depicted on the same scale with appropriate
legends.  (Of course, ignore if this is not the case).  If so, you
will need a different data structure for your data, I believe.

Bert Gunter

[...]

__
R-help@r-project.org 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.


[R] data manipulation question

2021-08-23 Thread Kai Yang via R-help
Hello List,
I wrote the script below to assign value to a new field DisclosureStatus.
my goal is if gl_resultsdisclosed=1 then DisclosureStatus=DISCLOSED
else if gl_resultsdisclosed=0 then DisclosureStatus= ATTEMPTED
else if gl_resultsdisclosed is missing and gl_discloseattempt1 is not missing 
then DisclosureStatus= ATTEMPTED
else missing


germlinepatients$DisclosureStatus <- 
              ifelse(germlinepatients$gl_resultsdisclosed==1, "DISCLOSED",
                ifelse(germlinepatients$ gl_resultsdisclosed==0, "ATTEMPTED", 
                   ifelse(is.na(germlinepatients$gl_resultsdisclosed) & 
germlinepatients$gl_discloseattempt1!='', "ATTEMPTED",
                                                           NA)))

the first 3 row give me right result, but the 3rd row does not. After checking 
the data, there are 23 cases are gl_resultsdisclosed is missing and 
gl_discloseattempt1 is not missing.  the code doesn't has any error message.
Please help 
thank you

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Abby Spurdle
There are some differences in R, between Windows and Linux.
You could try the 'shell' command instead.

#On Windows
?shell

On Tue, Aug 24, 2021 at 4:53 AM Anas Jamshed  wrote:
>
> I have the file GSE162562_RAW. First I untar them
> by untar("GSE162562_RAW.tar")
> then I am running like:
>  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")
>
>
> This is running fine in Linux but not in windows. What changes I
> should make to run this command in windows as well
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Andrew Simmons
Hello,


I tried downloading that file using 'utils::download.file' (which worked),
but then continued to complain about "damaged archive" when trying to use
'utils::untar'. However, it seemed to work when I downloaded the archive
manually. Finally, the solution I found is that you have to specify the
mode in which you're downloading the file. Something like:


URL <- "
https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
"
FILE <- file.path(tempdir(), basename(URL))


utils::download.file(URL, FILE, mode = "wb")
utils::untar(FILE, exdir = dirname(FILE))


worked perfectly for me. It seems to also work still on Ubuntu, but you can
let us know if you find it doesn't. I hope this helps!



On Mon, Aug 23, 2021 at 3:20 PM Anas Jamshed 
wrote:

> I am trying this URL: "
> https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
> "
>
> but it is not giving me any file
>
> On Mon, Aug 23, 2021 at 11:42 PM Andrew Simmons 
> wrote:
>
>> Hello,
>>
>>
>> I don't think you need to use a system command directly, I think
>> 'utils::untar' is all you need. I tried the same thing myself, something
>> like:
>>
>>
>> URL <- "https://exiftool.org/Image-ExifTool-12.30.tar.gz";
>> FILE <- file.path(tempdir(), basename(URL))
>>
>>
>> utils::download.file(URL, FILE)
>> utils::untar(FILE, exdir = dirname(FILE))
>>
>>
>> and it makes a folder "Image-ExifTool-12.30". It seems to work perfectly
>> fine in Windows 10 x64 build 19042. Can you send the specific file (or
>> provide a URL to the specific file) that isn't working for you?
>>
>> On Mon, Aug 23, 2021 at 12:53 PM Anas Jamshed 
>> wrote:
>>
>>> I have the file GSE162562_RAW. First I untar them
>>> by untar("GSE162562_RAW.tar")
>>> then I am running like:
>>>  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")
>>>
>>>
>>> This is running fine in Linux but not in windows. What changes I
>>> should make to run this command in windows as well
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Anas Jamshed
I am trying this URL: "
https://ftp.ncbi.nlm.nih.gov/geo/series/GSE162nnn/GSE162562/suppl/GSE162562_RAW.tar
"

but it is not giving me any file

On Mon, Aug 23, 2021 at 11:42 PM Andrew Simmons  wrote:

> Hello,
>
>
> I don't think you need to use a system command directly, I think
> 'utils::untar' is all you need. I tried the same thing myself, something
> like:
>
>
> URL <- "https://exiftool.org/Image-ExifTool-12.30.tar.gz";
> FILE <- file.path(tempdir(), basename(URL))
>
>
> utils::download.file(URL, FILE)
> utils::untar(FILE, exdir = dirname(FILE))
>
>
> and it makes a folder "Image-ExifTool-12.30". It seems to work perfectly
> fine in Windows 10 x64 build 19042. Can you send the specific file (or
> provide a URL to the specific file) that isn't working for you?
>
> On Mon, Aug 23, 2021 at 12:53 PM Anas Jamshed 
> wrote:
>
>> I have the file GSE162562_RAW. First I untar them
>> by untar("GSE162562_RAW.tar")
>> then I am running like:
>>  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")
>>
>>
>> This is running fine in Linux but not in windows. What changes I
>> should make to run this command in windows as well
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Need help to unzip files in Windows

2021-08-23 Thread Andrew Simmons
Hello,


I don't think you need to use a system command directly, I think
'utils::untar' is all you need. I tried the same thing myself, something
like:


URL <- "https://exiftool.org/Image-ExifTool-12.30.tar.gz";
FILE <- file.path(tempdir(), basename(URL))


utils::download.file(URL, FILE)
utils::untar(FILE, exdir = dirname(FILE))


and it makes a folder "Image-ExifTool-12.30". It seems to work perfectly
fine in Windows 10 x64 build 19042. Can you send the specific file (or
provide a URL to the specific file) that isn't working for you?

On Mon, Aug 23, 2021 at 12:53 PM Anas Jamshed 
wrote:

> I have the file GSE162562_RAW. First I untar them
> by untar("GSE162562_RAW.tar")
> then I am running like:
>  system("gunzip ~/Desktop/GSE162562_RAW/*.gz")
>
>
> This is running fine in Linux but not in windows. What changes I
> should make to run this command in windows as well
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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]]

__
R-help@r-project.org 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.


Re: [R] Selecting elements

2021-08-23 Thread Silvano Cesar da Costa
Hi,

I apologize for the confusion. I will try to be clearer in my explanation.
I believe that with the R script it becomes clearer.

I have 4 variables with 10 repetitions and each one receives a value,
randomly.
I order the dataset from largest to smallest value. I have to select 10
elements in
descending order of values, according to one of three schemes:

# 3A - 3B - 2C - 2D
# 2A - 5B - 0C - 3D
# 3A - 4B - 2C - 1D

If the first 3 elements (out of the 10 to be selected) are of the letter D,
automatically
the adopted scheme will be the second. So, I have to (following) choose 2A,
5B and 0C.
How to make the selection automatically?

I created two selection examples, with different schemes:


set.seed(123)

Var.1 = rep(LETTERS[1:4], 10)
Var.2 = sample(1:40, replace=FALSE)

data = data.frame(Var.1, Var.2)

(Order = data[order(data$Var.2, decreasing=TRUE), ])

# I must select the 10 highest values (),
# but which follow a certain scheme:
#
#  3A - 3B - 2C - 2D or
#  2A - 5B - 0C - 3D or
#  3A - 4B - 2C - 1D
#
# In this case, I started with the highest value that refers to the letter
C.
# Next comes only 1 of the letters B, A and D. All are selected once.
# The fifth observation is the letter C, completing 2 C values. In this
case,
# following the 3 adopted schemes, note that the second scheme has 0C,
# so this scheme is out.
# Therefore, it can be the first scheme (3A - 3B - 2C - 2D) or the
# third scheme (3A - 4B - 2C - 1D).
# The next letter to be completed is the D (fourth and seventh elements),
# among the 10 elements being selected. Therefore, the scheme adopted is
the
# first one (3A - 3B - 2C - 2D).
# Therefore, it is necessary to select 2 values with the letter B and 1
value
# with the letter A.
#
# Manual Selection -
# The end result is:
(Selected.data = Order[c(1,2,3,4,5,6,7,9,13,16), ])

# Scheme: 3A - 3B - 2C - 2D
sort(Selected.data$Var.1)


#--
# Second example: -
#--
set.seed(4)

Var.1 = rep(LETTERS[1:4], 10)
Var.2 = sample(1:40, replace=FALSE)

data = data.frame(Var.1, Var.2)
(Order = data[order(data$Var.2, decreasing=TRUE), ])

# The end result is:
(Selected.data.2 = Order[c(1,2,3,4,5,6,7,8,9,11), ])

# Scheme: 3A - 4B - 2C - 1D
sort(Selected.data.2$Var.1)

How to make the selection of the 10 elements automatically?

Thank you very much.

Prof. Dr. Silvano Cesar da Costa
Universidade Estadual de Londrina
Centro de Ciências Exatas
Departamento de Estatística

Fone: (43) 3371-4346


Em seg., 23 de ago. de 2021 às 05:05, PIKAL Petr 
escreveu:

> Hi
>
> Only I got your HTML formated mail, rest of the world got complete mess.
> Do not use HTML formating.
>
> As I got it right I wonder why in your second example you did not follow
> 3A - 3B - 2C - 2D
>
> as D were positioned 1st and 4th.
>
> I hope that you could use something like
>
> sss <- split(data$Var.2, data$Var.1)
> lapply(sss, cumsum)
> $A
>  [1]  38  73 105 136 166 188 199 207 209 210
>
> $B
>  [1]  39  67  92 115 131 146 153 159 164 168
>
> $C
>  [1]  40  76 105 131 152 171 189 203 213 222
>
> $D
>  [1]  37  71 104 131 155 175 192 205 217 220
>
> Now you need to evaluate this result according to your sets. Here the
> highest value (76) is in C so the set with 2C is the one you should choose
> and select you value according to this set.
>
> With
> > set.seed(666)
> > Var.1 = rep(LETTERS[1:4], 10)
> > Var.2 = sample(1:40, replace=FALSE)
> > data = data.frame(Var.1, Var.2)
> > data <- data[order(data$Var.2, decreasing=TRUE), ]
> > sss <- split(data$Var.2, data$Var.1)
> > lapply(sss, cumsum)
> $A
>  [1]  36  70 102 133 163 182 200 207 212 213
>
> $B
>  [1]  35  57  78  95 108 120 131 140 148 150
>
> $C
>  [1]  40  73 102 130 156 180 196 211 221 225
>
> $D
>  [1]  39  77 114 141 166 189 209 223 229 232
>
> Highest value is in D so either 3A - 3B - 2C - 2D  or 3A - 3B - 2C - 2D
> should be appropriate. And here I am again lost as both sets are same.
> Maybe you need to reconsider your statements.
>
> Cheers
> Petr
>
> From: Silvano Cesar da Costa 
> Sent: Friday, August 20, 2021 9:28 PM
> To: PIKAL Petr 
> Cc: r-help@r-project.org
> Subject: Re: [R] Selecting elements
>
> Hi, thanks you for the answer.
> Sorry English is not my native language.
>
> But you got it right.
> > As C is first and fourth biggest value, you follow third option and
> select 3 highest A, 3B 2C and 2D?
>
> I must select the 10 (not 15) highest values, but which follow a certain
> order:
> 3A - 3B - 2C - 2D or
> 2A - 5B - 0C - 3D or
> 3A - 3B - 2C - 2D
> I'll put the example in Excel for a better understanding (with 20 elements
> only).
> I must select 10 elements (the highest values of variable Var.2), which
> fit one of the 3 options above.
>
> Number
> Position
> Var.1
> Var.2
>
>
>
>
>
>
>
>
> 1
> 27
> C
> 40
>
>
>
>
>
>
>
>
> 2
> 30
> B
> 39
>
> Selected:
>
>
>
>
>
> 3
> 5
> A
> 38
>
> Number
> Position
> Var.1
> Var.2
>
>
>
> 4
> 16
> D
> 37
>
> 1
> 27
> C
> 40
>
>
>
> 5
> 23
> C
> 36
>
> 2
> 30
> B
> 39
>
> 3A - 3B -

[R] Need help to unzip files in Windows

2021-08-23 Thread Anas Jamshed
I have the file GSE162562_RAW. First I untar them
by untar("GSE162562_RAW.tar")
then I am running like:
 system("gunzip ~/Desktop/GSE162562_RAW/*.gz")


This is running fine in Linux but not in windows. What changes I
should make to run this command in windows as well

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Dynamic Creation and Use of Object Names

2021-08-23 Thread Bert Gunter
... and to add to Ivan's suggestions, **depending on what you are
trying to show with your grid of graphs,**  you may wish to consider
using ggplot's "facet" capabilities to assure that any quantitative
variables that you are encoding in the maps (e.g. by color, density
shading, etc.) are depicted on the same scale with appropriate
legends.  (Of course, ignore if this is not the case).  If so, you
will need a different data structure for your data, I believe.

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Aug 23, 2021 at 4:51 AM Dr Eberhard Lisse  wrote:
>
> Thank you,
>
> more to study :-)-O
>
> el
>
> On 23/08/2021 10:20, Ivan Krylov wrote:
> > On Mon, 23 Aug 2021 08:37:54 +0200
> > Dr Eberhard Lisse  wrote:
> >
> >> create the variables dynamically and add them to to
> >> the grid (dynamically, ie adding more countries)
> >
> > In my opinion, creating variables in the global environment
> > programmatically may lead to code that is hard to understand and debug
> > [*]. A key-value data structure (a named list or a separate
> > environment) would avoid the potential problems from variable name
> > collision. How about the following:
> >
> > 1. Put the countries in a vector: c('Namibia', 'Germany', ...)
> >
> > 2. Use lapply() to get a list of objects returned from your PICTURE
> > function
> >
> > 3. To save the pictures into individual files, loop over the list. You
> > can use setNames on the step 1 or 2 to make it a named list and keep
> > the country names together with their pictures:
> >
> > for (n in names(pictures)) {
> >   dev.new()
> >   print(pictures[[n]])
> >   ggsave(paste0(n, '.png'), ...)
> >   dev.off()
> > }
> >
> > (You can also use the png() device and plot straight to the file,
> > avoiding the need to draw the plot in the window for a fraction of a
> > second and for ggsave().)
> >
> > 4. Use the grobs= argument of grid.arrange() to pass the list of
> > objects to arrange instead of passing individual objects via ...
> >
>
>
> --
> To email me replace 'nospam' with 'el'
>
> __
> R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] Dynamic Creation and Use of Object Names

2021-08-23 Thread Dr Eberhard Lisse

Thank you,

more to study :-)-O

el

On 23/08/2021 10:20, Ivan Krylov wrote:

On Mon, 23 Aug 2021 08:37:54 +0200
Dr Eberhard Lisse  wrote:


create the variables dynamically and add them to to
the grid (dynamically, ie adding more countries)


In my opinion, creating variables in the global environment
programmatically may lead to code that is hard to understand and debug
[*]. A key-value data structure (a named list or a separate
environment) would avoid the potential problems from variable name
collision. How about the following:

1. Put the countries in a vector: c('Namibia', 'Germany', ...)

2. Use lapply() to get a list of objects returned from your PICTURE
function

3. To save the pictures into individual files, loop over the list. You
can use setNames on the step 1 or 2 to make it a named list and keep
the country names together with their pictures:

for (n in names(pictures)) {

  dev.new()
  print(pictures[[n]])
  ggsave(paste0(n, '.png'), ...)
  dev.off()
}

(You can also use the png() device and plot straight to the file,
avoiding the need to draw the plot in the window for a fraction of a
second and for ggsave().)

4. Use the grobs= argument of grid.arrange() to pass the list of
objects to arrange instead of passing individual objects via ...




--
To email me replace 'nospam' with 'el'

__
R-help@r-project.org 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.


Re: [R] Dynamic Creation and Use of Object Names

2021-08-23 Thread Ivan Krylov
On Mon, 23 Aug 2021 08:37:54 +0200
Dr Eberhard Lisse  wrote:

> create the variables dynamically and add them to to
> the grid (dynamically, ie adding more countries)

In my opinion, creating variables in the global environment
programmatically may lead to code that is hard to understand and debug
[*]. A key-value data structure (a named list or a separate
environment) would avoid the potential problems from variable name
collision. How about the following:

1. Put the countries in a vector: c('Namibia', 'Germany', ...)

2. Use lapply() to get a list of objects returned from your PICTURE
   function

3. To save the pictures into individual files, loop over the list. You
   can use setNames on the step 1 or 2 to make it a named list and keep
   the country names together with their pictures:
   
   for (n in names(pictures)) {
 dev.new()
 print(pictures[[n]])
 ggsave(paste0(n, '.png'), ...)
 dev.off()
   }

   (You can also use the png() device and plot straight to the file,
   avoiding the need to draw the plot in the window for a fraction of a
   second and for ggsave().)

4. Use the grobs= argument of grid.arrange() to pass the list of
   objects to arrange instead of passing individual objects via ...

-- 
Best regards,
Ivan

[*] For example, there's this FAQ for a different language:
https://perldoc.perl.org/perlfaq7#How-can-I-use-a-variable-as-a-variable-name?

__
R-help@r-project.org 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.


Re: [R] Selecting elements

2021-08-23 Thread PIKAL Petr
Hi

Only I got your HTML formated mail, rest of the world got complete mess. Do not 
use HTML formating.

As I got it right I wonder why in your second example you did not follow
3A - 3B - 2C - 2D

as D were positioned 1st and 4th.

I hope that you could use something like

sss <- split(data$Var.2, data$Var.1)
lapply(sss, cumsum)
$A
 [1]  38  73 105 136 166 188 199 207 209 210

$B
 [1]  39  67  92 115 131 146 153 159 164 168

$C
 [1]  40  76 105 131 152 171 189 203 213 222

$D
 [1]  37  71 104 131 155 175 192 205 217 220

Now you need to evaluate this result according to your sets. Here the highest 
value (76) is in C so the set with 2C is the one you should choose and select 
you value according to this set.

With
> set.seed(666)
> Var.1 = rep(LETTERS[1:4], 10)
> Var.2 = sample(1:40, replace=FALSE)
> data = data.frame(Var.1, Var.2)
> data <- data[order(data$Var.2, decreasing=TRUE), ]
> sss <- split(data$Var.2, data$Var.1)
> lapply(sss, cumsum)
$A
 [1]  36  70 102 133 163 182 200 207 212 213

$B
 [1]  35  57  78  95 108 120 131 140 148 150

$C
 [1]  40  73 102 130 156 180 196 211 221 225

$D
 [1]  39  77 114 141 166 189 209 223 229 232

Highest value is in D so either 3A - 3B - 2C - 2D  or 3A - 3B - 2C - 2D should 
be appropriate. And here I am again lost as both sets are same. Maybe you need 
to reconsider your statements.

Cheers
Petr

From: Silvano Cesar da Costa  
Sent: Friday, August 20, 2021 9:28 PM
To: PIKAL Petr 
Cc: r-help@r-project.org
Subject: Re: [R] Selecting elements

Hi, thanks you for the answer. 
Sorry English is not my native language.

But you got it right. 
> As C is first and fourth biggest value, you follow third option and select 3 
> highest A, 3B 2C and 2D?

I must select the 10 (not 15) highest values, but which follow a certain order:
3A - 3B - 2C - 2D or 
2A - 5B - 0C - 3D or
3A - 3B - 2C - 2D
I'll put the example in Excel for a better understanding (with 20 elements 
only). 
I must select 10 elements (the highest values of variable Var.2), which fit one 
of the 3 options above. 

Number
Position
Var.1
Var.2








1
27
C
40








2
30
B
39

Selected: 





3
5
A
38

Number
Position
Var.1
Var.2



4
16
D
37

1
27
C
40



5
23
C
36

2
30
B
39
 
3A - 3B - 2C - 2D
6
13
A
35

3
5
A
38



7
20
D
34

4
16
D
37

3A - 3B - 1C - 3D
8
12
D
33

5
23
C
36



9
9
A
32

6
13
A
35

2A - 5B - 0C - 3D
10
1
A
31

7
20
D
34



11
21
A
30

10
9
A
32



12
35
C
29

13
14
B
28



13
14
B
28

17
6
B
25



14
8
D
27








15
7
C
26








16
6
B
25





 
 
 
17
40
D
24





 
 
 
18
26
B
23





 
 
 
19
29
A
22





 
 
 
20
31
C
21





 
 
 



Second option (other data set):

Number
Position
Var.1
Var.2








1
36
D
20








2
11
B
19

Selected: 





3
39
A
18

Number
Position
Var.1
Var.2



4
24
D
17

1
36
D
20



5
34
B
16

2
11
B
19
 
3A - 3B - 2C - 2D
6
2
B
15

3
39
A
18



7
3
A
14

4
24
D
17
 
3A - 3B - 1C - 3D
8
32
D
13

5
34
B
16



9
28
D
12

6
2
B
15

2A - 5B - 0C - 3D
10
25
A
11

7
3
A
14



11
19
B
10

8
32
D
13



12
15
B
9

9
25
A
11



13
17
A
8

10
18
C
7



14
18
C
7








15
38
B
6








16
10
B
5








17
22
B
4








18
4
D
3








19
33
A
2








20
37
A
1










How to make the selection of these 10 elements that fit one of the 3 options 
using R?

Thanks,

Prof. Dr. Silvano Cesar da Costa
Universidade Estadual de Londrina
Centro de Ciências Exatas
Departamento de Estatística

Fone: (43) 3371-4346


Em sex., 20 de ago. de 2021 às 03:28, PIKAL Petr 
 escreveu:
Hallo

I am confused, maybe others know what do you want but could you be more 
specific?

Let say you have such data
set.seed(123)
Var.1 = rep(LETTERS[1:4], 10)
Var.2 = sample(1:40, replace=FALSE)
data = data.frame(Var.1, Var.2)

What should be the desired outcome?

You can sort
data <- data[order(data$Var.2, decreasing=TRUE), ]
and split the data
> split(data$Var.2, data$Var.1)
$A
 [1] 38 35 32 31 30 22 11  8  2  1

$B
 [1] 39 28 25 23 16 15  7  6  5  4

$C
 [1] 40 36 29 26 21 19 18 14 10  9

$D
 [1] 37 34 33 27 24 20 17 13 12  3

T inspect highest values. But here I am lost. As C is first and fourth biggest 
value, you follow third option and select 3 highest A, 3B 2C and 2D?

Or I do not understand at all what you really want to achieve.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Silvano Cesar 
> da
> Costa
> Sent: Thursday, August 19, 2021 10:40 PM
> To: mailto:r-help@r-project.org
> Subject: [R] Selecting elements
> 
> Hi,
> 
> I need to select 15 elements, always considering the highest values
> (descending order) but obeying the following configuration:
> 
> 3A - 4B - 0C - 3D or
> 2A - 5B - 0C - 3D or
> 3A - 3B - 2C - 2D
> 
> If I have, for example, 5 A elements as the highest values, I can only choose
> (first and third choice) or 2 (second choice) elements.
> 
> how to make this selection?
> 
> 
> library(dplyr)
> 
> Var.1 = rep(LETTERS[1:4], 10)
> Var.2 = sample(1:40, replace=FALSE